mmioDescend

The mmioDescend function descends into a chunk of a RIFF file that was opened by using themmioOpen function. It can also search for a given chunk.

本函数跳动入一个RIFF文件的一个块中。这个文件已经被mmioOpen函数打开,它也能搜索一个给定的块。

Syntax

MMRESULT mmioDescend(   HMMIO hmmio,   LPMMCKINFO lpck,   LPMMCKINFO lpckParent,   UINT wFlags ); 

 
     
 
     
 
     
 
     
 
     
 
     
 
    

Parameters

hmmio

File handle of an open RIFF file.

一个打开的RIFF文件的文件句柄

lpck

Pointer to a buffer that receives an MMCKINFO structure.

指秘一个缓冲区,它用来接收一个MMCKINFO结构

lpckParent

Pointer to an optional application-defined MMCKINFO structure identifying the parent of the chunk being searched for. If this parameter is not NULLmmioDescend assumes the MMCKINFOstructure it refers to was filled when mmioDescend was called to descend into the parent chunk, and mmioDescend searches for a chunk within the parent chunk. Set this parameter to NULL if no parent chunk is being specified.

指向一个可选的由应用程序定义的MMCKINFO结构,它标识这个正在搜索的块的父,如果这个参数不为NULL,本函数搜索一个块,局限于这个父块内部。设置这个参数为NULL,如果没有父块被指定。

wFlags

Search flags. If no flags are specified, mmioDescend descends into the chunk beginning at the current file position. The following values are defined.

搜索标志,如果没有标志被指定,本函数搜索这个块在当前文件位置。随后是被定义的值。

ValueMeaning
MMIO_FINDCHUNKSearches for a chunk with the specified chunk identifier.
MMIO_FINDLISTSearches for a chunk with the chunk identifier "LIST" and with the specified form type.
MMIO_FINDRIFFSearches for a chunk with the chunk identifier "RIFF" and with the specified form type.

 

Return value

Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.

Return codeDescription
MMIOERR_CHUNKNOTFOUND

The end of the file (or the end of the parent chunk, if given) was reached before the desired chunk was found.

 

Remarks

注意

A "RIFF" chunk consists of a four-byte chunk identifier (type FOURCC), followed by a four-byte chunk size (type DWORD), followed by the data portion of the chunk, followed by a null pad byte if the size of the data portion is odd. If the chunk identifier is "RIFF" or "LIST", the first four bytes of the data portion of the chunk are a form type or list type (type FOURCC).

一个“RIFF”块由一个四字节块标识,和随后的一个四字节块尺寸构成。随后是块的数据部分。再往后是一个null字节,如果数据部分的大小是奇数。如果块标识是"RIFF"或"LIST",块的数据部分的第一个四字节是一个结构类型或者list类型。


If you use mmioDescend to search for a chunk, make sure the file position is at the beginning of a chunk before calling the function. The search begins at the current file position and continues to the end of the file. If a parent chunk is specified, the file position should be somewhere within the parent chunk before calling mmioDescend. In this case, the search begins at the current file position and continues to the end of the parent chunk.

如果你使用本函数去搜索一个块,确定文件位置是在一个块的开始部分。搜索从当前文件位置然后到文件的结尾。如果一个父块被指定,呼叫本函数前,文件位置应该是父块中的某处,在这种情况下,搜索赔开始于当前文件位置,直到父块的结尾。


If mmioDescend is unsuccessful in searching for a chunk, the current file position is undefined. IfmmioDescend is successful, the current file position is changed. If the chunk is a "RIFF" or "LIST" chunk, the new file position will be just after the form type or list type (12 bytes from the beginning of the chunk). For other chunks, the new file position will be the start of the data portion of the chunk (8 bytes from the beginning of the chunk).

如果本函数搜索一个块时未成功,当前文件位置是不明确的。如果本函数成功,当前文件位置被改变。如果块是一个“RIFF”块或“LIST”块,新的文件位置将是格式类型或list类型(从这个块开始的12字节)后,对于其它块,新的文件位置将是这个块的数据开始部分。


本函数填充MMCKINFO结构,这个结构由lpck参数指定,用随后的信息。

The mmioDescend function fills the MMCKINFO structure pointed to by the lpck parameter with the following information:

  • The ckid member is the chunk. If the MMIO_FINDCHUNK, MMIO_FINDRIFF, or MMIO_FINDLIST flag is specified for wFlags, the MMCKINFO structure is also used to pass parameters tommioDescend. In this case, the ckid member specifies the four-character code of the chunk identifier, form type, or list type to search for.
  • The cksize member is the size, in bytes, of the data portion of the chunk. The size includes the form type or list type (if any), but does not include the 8-byte chunk header or the pad byte at the end of the data (if any).
  • The fccType member is the form type if ckid is "RIFF", or the list type if ckid is "LIST". Otherwise, it is NULL.
  • The dwDataOffset member is the file offset of the beginning of the data portion of the chunk. If the chunk is a "RIFF" chunk or a "LIST" chunk, this member is the offset of the form type or list type.
  • The dwFlags member contains other information about the chunk. Currently, this information is not used and is set to zero.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Mmsystem.h (include Windows.h)

Library

Winmm.lib

DLL

Winmm.dll

 

 

Send comments about this topic to Microsoft

Build date: 9/7/2011

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
好的,这里提供一个纯文字版的音乐播放器的代码,使用了C++标准库和Windows API: ```c++ #include <iostream> #include <Windows.h> #include <MMSystem.h> #include <conio.h> using namespace std; // 播放状态枚举 enum PlayState { STOPPED, PAUSED, PLAYING }; // 播放信息结构体 struct PlayInfo { PlayState state; string file_name; HWAVEOUT h_wave_out; WAVEFORMATEX wave_format; char *data_buf; DWORD data_len; DWORD cur_pos; }; // 音频数据处理回调函数 void CALLBACK wave_out_callback(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { PlayInfo *play_info = (PlayInfo *)dwInstance; if (uMsg == WOM_DONE) { play_info->cur_pos = 0; play_info->state = STOPPED; waveOutReset(hwo); } } // 加载音频文件 bool load_wave_file(const string &file_name, PlayInfo &play_info) { // 打开音频文件 HMMIO h_mmio = mmioOpen(const_cast<char *>(file_name.c_str()), NULL, MMIO_ALLOCBUF | MMIO_READ); if (h_mmio == NULL) { cerr << "Error: Cannot open file " << file_name << endl; return false; } // 查找WAVE格式块 MMCKINFO mmck_info_parent; mmck_info_parent.fccType = mmioFOURCC('W', 'A', 'V', 'E'); if (mmioDescend(h_mmio, &mmck_info_parent, NULL, MMIO_FINDRIFF) != MMSYSERR_NOERROR) { cerr << "Error: Cannot find WAVE chunk" << endl; mmioClose(h_mmio, 0); return false; } MMCKINFO mmck_info_child; mmck_info_child.ckid = mmioFOURCC('f', 'm', 't', ' '); if (mmioDescend(h_mmio, &mmck_info_child, &mmck_info_parent, MMIO_FINDCHUNK) != MMSYSERR_NOERROR) { cerr << "Error: Cannot find WAVE format chunk" << endl; mmioClose(h_mmio, 0); return false; } if (mmioRead(h_mmio, reinterpret_cast<HPSTR>(&play_info.wave_format), sizeof(WAVEFORMATEX)) != sizeof(WAVEFORMATEX)) { cerr << "Error: Cannot read WAVE format" << endl; mmioClose(h_mmio, 0); return false; } mmioAscend(h_mmio, &mmck_info_child, 0); // 查找数据块 mmck_info_child.ckid = mmioFOURCC('d', 'a', 't', 'a'); if (mmioDescend(h_mmio, &mmck_info_child, &mmck_info_parent, MMIO_FINDCHUNK) != MMSYSERR_NOERROR) { cerr << "Error: Cannot find WAVE data chunk" << endl; mmioClose(h_mmio, 0); return false; } play_info.data_len = mmck_info_child.cksize; play_info.data_buf = new char[play_info.data_len]; if (mmioRead(h_mmio, play_info.data_buf, play_info.data_len) != static_cast<LONG>(play_info.data_len)) { cerr << "Error: Cannot read WAVE data" << endl; delete[] play_info.data_buf; mmioClose(h_mmio, 0); return false; } mmioClose(h_mmio, 0); return true; } // 播放音频 void play_wave(PlayInfo &play_info) { if (play_info.state == STOPPED) { // 打开音频输出设备 if (waveOutOpen(&play_info.h_wave_out, WAVE_MAPPER, &play_info.wave_format, (DWORD_PTR)wave_out_callback, (DWORD_PTR)&play_info, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { cerr << "Error: Cannot open wave output device" << endl; return; } // 向音频输出设备写入数据 WAVEHDR wave_hdr; ZeroMemory(&wave_hdr, sizeof(WAVEHDR)); wave_hdr.lpData = play_info.data_buf; wave_hdr.dwBufferLength = play_info.data_len; if (waveOutPrepareHeader(play_info.h_wave_out, &wave_hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) { cerr << "Error: Cannot prepare wave header" << endl; waveOutClose(play_info.h_wave_out); return; } if (waveOutWrite(play_info.h_wave_out, &wave_hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) { cerr << "Error: Cannot write wave data" << endl; waveOutUnprepareHeader(play_info.h_wave_out, &wave_hdr, sizeof(WAVEHDR)); waveOutClose(play_info.h_wave_out); return; } // 更新播放状态 play_info.cur_pos = 0; play_info.state = PLAYING; } else if (play_info.state == PAUSED) { // 继续播放 waveOutRestart(play_info.h_wave_out); play_info.state = PLAYING; } } // 暂停音频 void pause_wave(PlayInfo &play_info) { if (play_info.state == PLAYING) { waveOutPause(play_info.h_wave_out); play_info.state = PAUSED; } } // 停止音频 void stop_wave(PlayInfo &play_info) { if (play_info.state != STOPPED) { waveOutReset(play_info.h_wave_out); play_info.cur_pos = 0; play_info.state = STOPPED; } } // 调节音量 void set_volume(PlayInfo &play_info, int volume) { if (volume < 0) { volume = 0; } else if (volume > 100) { volume = 100; } waveOutSetVolume(play_info.h_wave_out, static_cast<DWORD>((static_cast<UINT>(-1) * volume) / 100)); } int main(int argc, char **argv) { PlayInfo play_info; play_info.state = STOPPED; play_info.data_buf = NULL; play_info.data_len = 0; play_info.cur_pos = 0; while (true) { // 显示菜单 cout << "------------------" << endl; cout << "1. Load file" << endl; cout << "2. Play" << endl; cout << "3. Pause" << endl; cout << "4. Stop" << endl; cout << "5. Set volume" << endl; cout << "6. Exit" << endl; cout << "------------------" << endl; cout << "Current file: " << play_info.file_name << endl; cout << "Current position: " << play_info.cur_pos << " / " << play_info.data_len << endl; cout << "Current state: "; switch (play_info.state) { case STOPPED: cout << "STOPPED" << endl; break; case PAUSED: cout << "PAUSED" << endl; break; case PLAYING: cout << "PLAYING" << endl; break; } cout << "Current volume: " << (waveOutGetVolume(play_info.h_wave_out) * 100) / static_cast<UINT>(-1) << endl; cout << "Please enter your choice: "; // 处理用户输入 char choice = _getch(); cout << choice << endl; switch (choice) { case '1': { // 加载文件 string file_name; cout << "Please enter the file name: "; cin >> file_name; cout << endl; if (load_wave_file(file_name, play_info)) { play_info.file_name = file_name; play_info.cur_pos = 0; play_info.state = STOPPED; cout << "File loaded successfully" << endl; } break; } case '2': // 播放

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值