当前位置: 代码迷 >> Windows Mobile >> Windows mobile5.0上的mp3播放器只能播放wav格式的·
  详细解决方案

Windows mobile5.0上的mp3播放器只能播放wav格式的·

热度:3955   发布时间:2013-02-26 00:00:00.0
Windows mobile5.0下的mp3播放器只能播放wav格式的···
本帖最后由 mengfeiyulu 于 2012-06-05 15:57:17 编辑
为什么我在Windows mobile 5.0下编写的MP3播放器只能播放wav格式的歌曲囧,怎么才能播放MP3文件呢?

"playControl.h"

#pragma once
#include <streams.h>
#pragma comment (lib,"Ole32.lib")
#pragma comment (lib,"Strmiids.lib")


#define HELPER_RELEASE(x) { if (x) x->Release(); x = NULL; }
#define WM_GRAPHNOTIFY  WM_USER+1

class CPlayControl
{
public:
CPlayControl(void);
public:
~CPlayControl(void);
public:
IGraphBuilder *pGB; //这是directshow的核心
IMediaControl *pMC; //帮我们连接filter(媒体文件,解码器等)          
//简单的说,它帮我们简单地打开和播放文件.
IMediaEventEx *pME; //处理过滤器图表的事件
IVideoWindow  *pVW; //用这个来控制directshow的视频窗口
IBasicAudio   *pBA; //用于控制音频流的音量和平衡
IBasicVideo   *pBV;     //用于设置视频特性,如视频显示的目的区域和源区域
IMediaSeeking *pMS; //提供搜索数据流位置和设置播放速率的方法,播放位置

enum PLAYSTATE { RUNING, PAUSED, STOPPED, INIT };

public:

PLAYSTATE playControlInfo;
HWND      ghApp;

public:

bool SetNotifyWindow(HWND inWindow);
bool Create();
bool RenderFile(WCHAR *szFile);
bool buttonPlay();
bool buttonPause();
void buttonStop();
void CloseInterfaces(void);
bool ListPlay(WCHAR *szFile);
float GetAlltime();
float GetCurrentPosition();
bool SetCurrentPosition(double inPosition) ;
bool Running();
void SetVol(int m_vol);

IMediaEventEx * GetEventHandle();
};


"playControl.cpp"


#include "StdAfx.h"
#include "PlayControl.h"

CPlayControl::CPlayControl(void)
{
IGraphBuilder *pGB = NULL;
IMediaControl *pMC = NULL;
IMediaEventEx *pME = NULL;
IVideoWindow  *pVW = NULL;
IBasicAudio   *pBA = NULL;
IBasicVideo   *pBV = NULL;
IMediaSeeking *pMS = NULL;
playControlInfo = STOPPED;
ghApp = 0;
}

CPlayControl::~CPlayControl(void)
{
CoUninitialize();
}

void CPlayControl::CloseInterfaces(void)
{
HELPER_RELEASE(pMC);
HELPER_RELEASE(pME);
HELPER_RELEASE(pMS);
HELPER_RELEASE(pBV);
HELPER_RELEASE(pBA);
HELPER_RELEASE(pVW);
HELPER_RELEASE(pGB);

// No current media state
playControlInfo = INIT;

}


bool CPlayControl::Create()
{
if(FAILED(CoInitialize(NULL)))
return false;

// Get the interface for DirectShow's GraphBuilder
if( SUCCEEDED( CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGB )))
{
HRESULT hr = NOERROR;
// QueryInterface for DirectShow interfaces
hr |= (pGB->QueryInterface(IID_IMediaControl, (void **)&pMC));
hr |= (pGB->QueryInterface(IID_IMediaEventEx, (void **)&pME));
hr |= (pGB->QueryInterface(IID_IMediaSeeking, (void **)&pMS));

// Query for video interfaces, which may not be relevant for audio files
  相关解决方案