/**
*
* @brief Definition of CAudioPlayerEngine
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
#include "AudioPlayerEngine.h"
#include <eikenv.h>
#include <stringloader.h>
#include <barsread.h>
#include <aknutils.h>
#include "AudioPlayer.rsg"
#include "AudioPlayer.loc"
_LIT(KToPlayFileWav, "\\Ring.wav");
_LIT(KToPlayFileMidi, "\\Fur-Elise.mid");
_LIT(KToPlayFileStream, "\\Stream.pcm");
const TInt KToneFrequency = 3000;
const TInt KToneDuration = 4000000;
const TInt KToneVolumeDenominator = 2;
/**
* C++ constructor
*/
CAudioPlayerEngine::CAudioPlayerEngine(MAudioPlayerEngineObserver& aObserver)
:iObserver(aObserver),
iState(EStopped)
{
}
/**
* Destructor.
*/
CAudioPlayerEngine::~CAudioPlayerEngine()
{
Stop();
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CAudioPlayerEngine popping
* the constructed object from the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CAudioPlayerAppView
*/
CAudioPlayerEngine* CAudioPlayerEngine::NewL(MAudioPlayerEngineObserver& aObserver)
{
CAudioPlayerEngine* self = new (ELeave) CAudioPlayerEngine(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
/**
* Symbian 2nd phase constructor.
* Empty implementation
*/
void CAudioPlayerEngine::ConstructL()
{
}
/**
* MMdaAudioToneObserver derivation
* This has been called as a result of NewL() being called on the tone player
* the tone utility is now ready for playing
*
* @param aError Error code to inform us if preparation has successfully completed
*
*/
void CAudioPlayerEngine::MatoPrepareComplete(TInt aError)
{
if (aError)
{
Stop();
}
else
{
iPlayerTone->SetVolume(iPlayerTone->MaxVolume() / KToneVolumeDenominator);
iPlayerTone->Play();
}
}
/**
* MMdaAudioToneObserver derivation
* This is called when tone playing completes and informs the
* MAudioPlayerEngineObserver playing has finished.
*
* @param aError Error code to inform us if playing has successfully completed
*/
void CAudioPlayerEngine::MatoPlayComplete(TInt /*aError*/)
{
iState = EStopped;
delete iPlayerTone;
iPlayerTone = NULL;
TRAPD(err, iObserver.HandlePlayingStoppedL());
}
/**
* MMdaAudioPlayerCallback derivation
* This has been called as a result of NewFilePlayerL() being called on the file player
* the player utility is now ready for playing
*
* @param aError Status of the audio sample after initialization
* @param aDuration Duration of the audio sample
*/
void CAudioPlayerEngine::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
{
if (aError == KErrNone)
{
iPlayerFile->SetVolume(iPlayerFile->MaxVolume() / KToneVolumeDenominator);
iPlayerFile->Play();
}
else
{
Stop();
}
}
/**
* MMdaAudioPlayerCallback derivation
* This has been called as a result of playing being completed
*
* @param aError Error code to inform if playing has successfully completed
*/
void CAudioPlayerEngine::MapcPlayComplete(TInt /*aError*/)
{
iState = EStopped;
delete iPlayerFile;
iPlayerFile = NULL;
TRAPD(err, iObserver.HandlePlayingStoppedL());//播放完通知给了它的观察者VIEW
// if (aError == KErrNone)
// {
// iPlayerFile->Close(); /* Closes the current audio clip, so can allow another clip to be opened). */
//
// iPlayerFile->OpenFileL(_L("c:\data\Fur-Elise.mid")); /* 打开另一个音频文件并重复播放流程 */
//
// }
// else
//
// {
// iPlayerFile->Stop();
// }
}
/**
* MMdaAudioOutputStreamCallback derivation
* This has been called as a result of NewL() being called on the stream player
* in order to play the stream, we must 1st write the stream buffer to the client
* once this has been done, the stream will begin playing automatically
*
* @param aError Error code to indicate if open succeeded
*/
void CAudioPlayerEngine::MaoscOpenComplete(TInt aError)
{
if (aError == KErrNone)
{
TRAPD(err, iPlayerStream->WriteL(*iStreamBuffer));
}
else
{
Stop();
}
}
/**
* This has been called in response to WriteL() being called on the stream player
* or in response to Stop() being called on the stream player. in the latter case,
* aError is equal to KErrAbort.
* Otherwise, we add iStreamBuffer to the client queue, so that it will be repeated,
* when the last buffer has finished
*
* @param aError Error code to indicate if copy was successful
* @param aBuffer A reference to the descriptor that has been copied to the server
*/
void CAudioPlayerEngine::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
{//open完调用该回掉,
if (aError == KErrNone)
{
TRAPD(err, iPlayerStream->WriteL(*iStreamBuffer))//完了后指向第一个没有写的数据
iPlayerStream->SetVolume(iPlayerStream->MaxVolume() / KToneVolumeDenominator);
}//所有声音播放完后,MaoscPlayComplete(TInt /*aError*/)被回掉
}
/**
* Callback when playback finishes
*
* @param aError Error code indicates why playback was terminated
*/
void CAudioPlayerEngine::MaoscPlayComplete(TInt /*aError*/)
{
iState = EStopped;
delete iPlayerStream;
iPlayerStream = NULL;
delete iStreamBuffer;
iStreamBuffer = NULL;
delete [] iStreamData;
iStreamData = NULL;
TRAPD(err, iObserver.HandlePlayingStoppedL());
}
//PLAYER FUNCTIONS
/**
* Constructs the tone player;
* This will lead to a call to MapcInitComplete()
*/
void CAudioPlayerEngine::PlayToneL()
{
iState = EPlaying;
iPlayerTone = CMdaAudioToneUtility::NewL(*this);
iPlayerTone->PrepareToPlayTone(KToneFrequency, TTimeIntervalMicroSeconds(KToneDuration));//以一定的频率发出声音
}
/**
* Constructs the file player;
* This will lead to a call to MapcInitComplete()
*/
void CAudioPlayerEngine::PlayWavL()
{
TFileName wavFile(KToPlayFileWav);
User::LeaveIfError(CompleteWithAppPath(wavFile));
iState = EPlaying;
iPlayerFile = CMdaAudioPlayerUtility::NewFilePlayerL(wavFile, *this);//传this是观察者
}
/**
* Constructs the file player;
* This will lead to a call to MapcInitComplete()
* Note: playing midi files can only be supported on device; it is not supported under WINS
*/
void CAudioPlayerEngine::PlayMidiL()
{
#ifndef __WINS__
TFileName midiFile(KToPlayFileMidi);
User::LeaveIfError(CompleteWithAppPath(midiFile));
iState = EPlaying;
iPlayerFile = CMdaAudioPlayerUtility::NewFilePlayerL(midiFile, *this);
#endif
}
/**
* Constructs the stream player
* This will lead to a call to MaoscOpenComplete()
*/
void CAudioPlayerEngine::PlayStreamL()
{
// open the file and load it into the buffers
RFs fs;
CleanupClosePushL(fs); // PUSH
User::LeaveIfError(fs.Connect());
RFile file;
CleanupClosePushL(file); // PUSH
TFileName streamFile(KToPlayFileStream);
User::LeaveIfError(CompleteWithAppPath(streamFile));
User::LeaveIfError(file.Open(fs, streamFile, EFileRead | EFileShareReadersOnly));
TInt fileSize = 0;
file.Size(fileSize);
iStreamData = new (ELeave) TUint8[fileSize];
iStreamBuffer = new (ELeave) TPtr8(iStreamData, fileSize, fileSize);
file.Read(*iStreamBuffer);
CleanupStack::PopAndDestroy(2); // file & fs
iState = EPlaying;
iPlayerStream = CMdaAudioOutputStream::NewL(*this);
iPlayerStream->Open(&iStreamSettings);
}
/**
* Stops whatever is playing and deletes the player
*/
void CAudioPlayerEngine::Stop()
{
if (iPlayerTone)
{
iPlayerTone->CancelPlay();
}
if (iPlayerFile)
{
iPlayerFile->Stop();
}
if (iPlayerStream)
{
iPlayerStream->Stop();
}
delete iPlayerTone;
iPlayerTone = NULL;
delete iPlayerFile;
iPlayerFile = NULL;
delete iPlayerStream;
iPlayerStream = NULL;
delete iStreamBuffer;
iStreamBuffer = NULL;
delete [] iStreamData;
iStreamData = NULL;
iState = EStopped;
}
没有合适的资源?快使用搜索试试~ 我知道了~
symbian 播放器源码
共75个文件
cpp:10个
h:8个
xml:5个
2星 需积分: 10 31 下载量 28 浏览量
2010-09-02
11:58:11
上传
评论
收藏 631KB RAR 举报
温馨提示
symbian 播放器源码symbian 播放器源码symbian 播放器源码symbian 播放器源码symbian 播放器源码symbian 播放器源码symbian 播放器源码symbian 播放器源码symbian 播放器源码
资源推荐
资源详情
资源评论
收起资源包目录
AudioPlayer.rar (75个子文件)
AudioPlayer
aif
list_icon_mask.bmp 294B
context_pane_icon.bmp 3KB
Thumbs.db 9KB
AudioPlayerAif.rss 304B
list_icon.bmp 2KB
context_pane_icon_mask.bmp 414B
inc
AudioPlayerAppUi.h 2KB
AudioPlayerAppView.h 3KB
AudioPlayer.l01 808B
MyPlayer.h 1KB
AudioPlayer.pan 654B
AudioPlayer.loc 192B
AudioPlayerDocument.h 2KB
AudioPlayer_0xE007A774.rsg 549B
AudioPlayerApplication.h 1KB
AudioPlayer.hrh 646B
AudioPlayerEngine.h 2KB
AudioPlayer_0xE007A774_reg.rsg 0B
AudioPlayerView.h 1KB
AudioPlayerTimer.h 1021B
AudioPlayer.ncb 107KB
data
AudioPlayer_reg.rss 751B
AudioPlayer_caption.rss 300B
AudioPlayer.rss 4KB
AudioPlayer_reg.rss.I 6KB
AudioPlayer.rls 1KB
AudioPlayer.rss.I 134KB
sis
AudioPlayer_S60_3_X_v_1_0_0.sis 171KB
backup_registration.xml 144B
AudioPlayer_S60_3_X_v_1_0_0.pkg 2KB
mycert.cer 2KB
mykey.key 1KB
AudioPlayer_S60_3_X_v_1_0_0.sisx 171KB
.rnd 1024B
install
AudioPlayer.pkg 1KB
AudioPlayer.sln 769B
AudioPlayer.vcproj 7KB
gfx
qgn_menu_AudioPlayer.svg 4KB
help
build_help.mk 1KB
AudioPlayer_0xE007A774.hlp.hrh 251B
temp
AudioPlayer_0xE007A774.cshlp.xml 1KB
AudioPlayer_0xE007A774.hlp 3KB
AudioPlayer.xml 491B
Custom.xml 660B
AudioPlayer.cshlp 559B
AudioPlayer.vcproj.LYL-4A7CFEB34A8.liyanlei.user 916B
src
MyPlayer.cpp 3KB
AudioPlayerTimer.cpp 1KB
AudioPlayer.cpp 542B
AudioPlayerAppView.cpp 5KB
AudioPlayerApplication.cpp 1KB
AudioPlayerView.cpp 5KB
AudioPlayerDocument.cpp 3KB
AudioPlayerAppUi.cpp 4KB
AudioPlayerEngine.cpp 8KB
.project 523B
.cproject 13KB
sounds
Ring.wav 17KB
Op90.mid 44KB
Stream.pcm 36KB
ddddd.wav 166KB
Fur-Elise.mid 9KB
group
bld.inf 488B
AudioPlayer.mmp.orig 1KB
AUDIOPLAYER.DSP 11KB
AUDIOPLAYER.ncb 57KB
AudioPlayer.mmp 1KB
AUDIOPLAYER.UID.CPP 188B
Icons_scalable_dc.mk 1KB
AUDIOPLAYER.DSW 543B
ABLD.BAT 321B
AUDIOPLAYER.OPT 53KB
AUDIOPLAYER.SUP.MAKE 10KB
AudioPlayer.suo 8KB
AudioPlayer-SymbianOS-properties.xml 2KB
共 75 条
- 1
资源评论
- fq4607916602012-06-18在模拟器上运行不起来
liyong8267198
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 常用工具配置docker,elasticsearch,minio,nfs,nginx,tippercane,vsftp
- 基于IIC接口E2PROM(AT24C64)芯片FPGA读写VERILOG 设计源码+仿真激励文件.zip
- 基于FPGA深度学习的Block 模块方案实战,适合FPGA初学者
- 20225T9050袁凤(1).py
- Rsa算法详解.docx
- Youren Shang InClassQuiz.ipynb
- code-qat.zip
- usb-serial-for-android
- drools决策表示例Excel文件
- AD5724芯片FPGA Verilog驱动源码+4通道12bit位宽的DAC芯片AD5724技术手册.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功