标题: [原创]利用LabWindows/CVI制作音频播放器 [打印本页]
作者: wangjianxin2001 时间: 2006-12-8 14:32 标题: [原创]利用LabWindows/CVI制作音频播放器
大家都知道,MP3、MID、WAV、WMA等格式的音频文件可以通过调用底层函数来实现播放的! 在这里,我介绍利用自己编制的音频解码器来播放音乐的例子,其中,已经将解码器封装到了动态库里,只给出了接口函数及调用规则!
动态库头文件为:
//打开音频文件 pathname为文件路径名
int __stdcall opensong (char *pathname);
//播放音频文件 position为播放的起始位置
int __stdcall playsong (char *pathname, int position);
//暂停播放
int __stdcall pausesong (char *pathname);
//停止播放,并关闭设备
int __stdcall stopsong (char *pathname);
//播放状态 kind 0:所播放文件的长度 1:播放状态,为"playing,pause,stoped"等 2:播放的进度,以毫秒计
int __stdcall statussong (char *pathname, int kind, char *status);
//关于对话框
void about(void);
应用程序界面为:
程序代码为:
#include
#include
#include
#include "exe.h"
#include "mci.h"
static char pathname[MAX_PATHNAME_LEN];
static int panelHandle;
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "exe.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK OkCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int status;
char mode[128];
switch (event)
{
case EVENT_COMMIT:
status = FileSelectPopup ("", "*.mp3", "*.mp3;*.wav;*.mid;*.wma", "打开音频文件", VAL_OK_BUTTON, 0, 0, 1, 1, pathname);
opensong(pathname);
playsong(pathname, 0);
statussong(pathname, 1, mode);
SetCtrlVal (panelHandle, PANEL_STRING, mode);
break;
}
return 0;
}
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
int CVICALLBACK stop (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char status[128];
switch (event)
{
case EVENT_COMMIT:
stopsong(pathname);
statussong(pathname, 1, status);
SetCtrlVal (panelHandle, PANEL_STRING, status);
break;
}
return 0;
}
int CVICALLBACK pause (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char status[128];
switch (event)
{
case EVENT_COMMIT:
pausesong(pathname);
statussong(pathname, 1, status);
SetCtrlVal (panelHandle, PANEL_STRING, status);
break;
}
return 0;
}
int CVICALLBACK continu (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char status[128];
int position = 0;
switch (event)
{
case EVENT_COMMIT:
status[0] = '\0';
statussong(pathname, 2, status);
Fmt(&position, "%i<%s", status);
playsong(pathname, position);
status[0] = '\0';
statussong(pathname, 1, status);
SetCtrlVal (panelHandle, PANEL_STRING, status);
break;
}
return 0;
}
int CVICALLBACK pre (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char status[128];
int position;
switch (event)
{
case EVENT_COMMIT:
statussong(pathname, 1, status);
SetCtrlVal (panelHandle, PANEL_STRING, status);
statussong(pathname, 2, status);
Fmt (&position, "%i<%s", status);
position += 5000;
playsong(pathname, position);
break;
}
return 0;
}
int CVICALLBACK back (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char status[128];
int position;
switch (event)
{
case EVENT_COMMIT:
statussong(pathname, 1, status);
SetCtrlVal (panelHandle, PANEL_STRING, status);
statussong(pathname, 2, status);
Fmt (&position, "%i<%s", status);
position -= 5000;
playsong(pathname, position);
break;
}
return 0;
}
int CVICALLBACK len (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char status[128];
switch (event)
{
case EVENT_COMMIT:
statussong(pathname, 0, status);
SetCtrlVal (panelHandle, PANEL_STRING, status);
break;
}
return 0;
}
int CVICALLBACK aboutme (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
about();
break;
}
return 0;
}
KLcmHkHw.rar (38.21 KB)
转自:小信的博客
网址:http://blog.sina.com.cn/u/1265070197
[此贴子已经被作者于2006-12-9 12:52:46编辑过]
附件: [[原创]利用LabWindows/CVI制作音频播放器] KLcmHkHw.rar (2006-12-8 14:32, 38.21 KB) / 下载次数 371
http://bbs.eccn.com/attachment.php?aid=448&k=a32793ac83730cd47156671040606b74&t=1732335119&sid=V1vTg7
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) |
Powered by Discuz! 7.0.0 |