📄 oggplay.cpp
字号:
{
if (iSettings.iRepeat)
SetRepeat(EFalse);
else
SetRepeat(ETrue);
}
void
COggPlayAppUi::SetRepeat(TBool aRepeat)
{
iSettings.iRepeat = aRepeat;
iSongList->SetRepeat(aRepeat);
iAppView->UpdateRepeat();
}
#if !defined(MULTI_THREAD_PLAYBACK)
void COggPlayAppUi::SetProcessPriority()
{
#if !defined(__WINS__) //FIXFIXME
CEikonEnv::Static()->WsSession().ComputeMode(RWsSession::EPriorityControlDisabled);
RProcess P;
TFindProcess fp(_L("OggPlay*"));
TFullName fn;
if (fp.Next(fn)==KErrNone) {
int err= P.Open(fn);
if (err==KErrNone) {
P.SetPriority(EPriorityHigh);
P.Close();
} else {
TBuf<256> buf;
iEikonEnv->ReadResource(buf, R_OGG_ERROR_3);
buf.AppendNum(err);
User::InfoPrint(buf);
}
}
else {
TBuf<256> buf;
iEikonEnv->ReadResource(buf, R_OGG_ERROR_4);
User::InfoPrint(buf);
}
#endif
}
void COggPlayAppUi::SetThreadPriority()
{
#if !defined(__WINS__) //FIXFIXME
//CEikonEnv::Static()->WsSession().ComputeMode(RWsSession::EPriorityControlDisabled);
RThread T;
TFindThread ft(_L("OggPlay*"));
TFullName fn;
if (ft.Next(fn)==KErrNone) {
int err= T.Open(fn);
if (err==KErrNone) {
#if defined(MOTOROLA)
T.SetPriority(EPriorityAbsoluteForeground);
#else
T.SetPriority(EPriorityAbsoluteHigh);
#endif
T.Close();
} else {
TBuf<256> buf;
iEikonEnv->ReadResource(buf, R_OGG_ERROR_5);
buf.AppendNum(err);
User::InfoPrint(buf);
}
}
else {
TBuf<256> buf;
iEikonEnv->ReadResource(buf, R_OGG_ERROR_6);
User::InfoPrint(buf);
}
#endif
}
#endif
TBool COggPlayAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/, TFileName& /*aDocumentName*/,const TDesC8& /*aTail*/)
{
return ETrue;
}
void COggPlayAppUi::OpenFileL(const TDesC& aFileName)
{
iEmbeddedFileName = aFileName;
iIsRunningEmbedded = ETrue;
}
TInt COggPlayAppUi::FileSize(const TDesC& aFileName)
{
RFile file;
TInt err = file.Open(iCoeEnv->FsSession(), aFileName, EFileShareReadersOnly);
if (err != KErrNone)
return 0;
TInt fileSize(0);
file.Size(fileSize);
file.Close();
return fileSize;
}
void COggPlayAppUi::SetVolumeGainL(TGainType aNewGain)
{
iOggPlayback->SetVolumeGain(aNewGain);
iSettings.iGainType = aNewGain;
#if defined(SERIES60)
#if defined(MULTI_THREAD_PLAYBACK)
iPlaybackOptionsView->VolumeGainChangedL();
#else
iSettingsView->VolumeGainChangedL();
#endif
#endif
}
#if defined(MULTI_THREAD_PLAYBACK)
void COggPlayAppUi::SetBufferingModeL(TBufferingMode aNewBufferingMode)
{
TInt err = ((COggPlayback *) iOggPlayback)->SetBufferingMode(aNewBufferingMode);
if (err == KErrNone)
iSettings.iBufferingMode = aNewBufferingMode;
else
{
// Pop up a message (reset the value in the playback options too)
TBuf<256> buf, tbuf;
iEikonEnv->ReadResource(tbuf, R_OGG_ERROR_20);
iEikonEnv->ReadResource(buf, R_OGG_ERROR_29);
iOggMsgEnv->OggErrorMsgL(tbuf, buf);
#if defined(SERIES60)
iPlaybackOptionsView->BufferingModeChangedL();
#endif
}
}
void COggPlayAppUi::SetThreadPriority(TStreamingThreadPriority aNewThreadPriority)
{
((COggPlayback *) iOggPlayback)->SetThreadPriority(aNewThreadPriority);
iSettings.iThreadPriority = aNewThreadPriority;
}
#endif
void COggPlayAppUi::SetAlarm(TBool aAlarmActive)
{
iSettings.iAlarmActive = aAlarmActive;
iAppView->SetAlarm();
}
void COggPlayAppUi::SetAlarmTime()
{
iAppView->SetAlarm();
}
// COggSongList class
COggSongList::COggSongList(COggPlayAppView* aAppView, CAbsPlayback* aOggPlayback)
: iAppView(aAppView), iOggPlayback(aOggPlayback)
{
}
void COggSongList::ConstructL(COggSongList* aSongList)
{
if (aSongList)
{
// Copy the state from the other song list
RPointerArray<TOggFile>& fileList = aSongList->iFileList;
TInt count = fileList.Count();
for (TInt i = 0 ; i<count ; i++)
iFileList.Append(fileList[i]);
iPlayingIdx = aSongList->iPlayingIdx;
iNewFileList = aSongList->iNewFileList;
}
else
{
iPlayingIdx = ENoFileSelected;
iNewFileList = EFalse;
}
}
COggSongList::~COggSongList()
{
iFileList.Close();
iPlayListStack.Close();
}
void
COggSongList::SetPlayingFromListBox(TInt aPlaying)
{
// Change the currently played song
// It is possible that the current list is not the one on the list box on screen
// (User has navigated while playing tune).
// Update the file list, according to what is displayed in the list box.
iFileList.Reset();
iNewFileList = ETrue;
iPlayingIdx = ENoFileSelected;
for (TInt i=0; i<iAppView->GetTextArray()->Count(); i++) {
if (iAppView->HasAFileName(i))
{
// We're dealing with a file, not the "back" button or something similar
iFileList.Append(iAppView->GetFile(i));
if (i == aPlaying)
iPlayingIdx = iFileList.Count()-1;
}
}
SetPlaying(iPlayingIdx);
}
void
COggSongList::SetPlaying(TInt aPlaying, TBool aPreviousSong)
{
iPlayingIdx = aPlaying;
if (aPlaying != ENoFileSelected)
{
TOggFile* file = iFileList[aPlaying];
if (file->FileType() == TOggFile::EPlayList)
{
// Playing a new playlist, so reset the playlist stack and set iPlaylist, iPlayListIdx
iPlayListStack.Reset();
iPlayList = (TOggPlayList*) file;
if (aPreviousSong)
iPlayListIdx = iPlayList->Count()-1;
else
iPlayListIdx = 0;
file = (*iPlayList)[iPlayListIdx];
while (file->FileType() == TOggFile::EPlayList)
{
// Another playlist. Push the current playlist onto the stack and get the next file
TOggPlayListStackEntry playListStackEntry(iPlayList, iPlayListIdx);
TInt err = iPlayListStack.Push(playListStackEntry);
if (err != KErrNone)
{
iPlayListStack.Reset();
return;
}
iPlayList = (TOggPlayList*) file;
if (aPreviousSong)
iPlayListIdx = iPlayList->Count()-1;
else
iPlayListIdx = 0;
file = (*iPlayList)[iPlayListIdx];
}
}
else
iPlayList = NULL;
}
if (iPlayingIdx != ENoFileSelected)
{
iAppView->SelectFile(iFileList[iPlayingIdx]);
#if !defined(DELAY_AUDIO_STREAMING_START)
iAppView->Update();
#endif
}
else
iAppView->Update();
}
const TOggFile*
COggSongList::GetPlayingFile()
{
if (iPlayingIdx != ENoFileSelected)
return ( iFileList[iPlayingIdx] );
return(NULL);
}
const TDesC&
COggSongList::GetPlaying()
{
if (iPlayingIdx == ENoFileSelected)
return KNullDesC;
TOggFile* playingFile = iFileList[iPlayingIdx];
if (playingFile->FileType() == TOggFile::EPlayList)
playingFile = (*iPlayList)[iPlayListIdx];
return(*(playingFile->iFileName));
}
const TBool
COggSongList::AnySongPlaying()
{
if (iPlayingIdx == ENoFileSelected)
return EFalse;
else
return ETrue;
}
const TBool
COggSongList::IsSelectedFromListBoxCurrentlyPlaying()
{
TInt idx = iAppView->GetSelectedIndex();
if (iAppView->HasAFileName(idx))
{
if ( GetPlayingFile() == iAppView->GetFile(idx) )
{
return (ETrue);
}
}
return(EFalse);
}
void
COggSongList::SetRepeat(TBool aRepeat)
{
iRepeat = aRepeat;
}
// COggNormalPlay class
COggNormalPlay* COggNormalPlay::NewL(COggPlayAppView* aAppView, CAbsPlayback* aOggPlayback, COggSongList* aSongList)
{
COggNormalPlay* self = new(ELeave) COggNormalPlay(aAppView, aOggPlayback);
CleanupStack::PushL(self);
self->ConstructL(aSongList);
CleanupStack::Pop(self);
return self;
}
COggNormalPlay::COggNormalPlay(COggPlayAppView* aAppView, CAbsPlayback* aOggPlayback)
: COggSongList(aAppView, aOggPlayback)
{
}
COggNormalPlay::~COggNormalPlay()
{
}
const TDesC& COggNormalPlay::GetNextSong()
{
TInt nSongs= iFileList.Count();
if ( (iPlayingIdx == ENoFileSelected) || (nSongs <=0) )
{
SetPlaying(ENoFileSelected);
return(KNullDesC);
}
TOggFile* file = iFileList[iPlayingIdx];
if (file->FileType() == TOggFile::EPlayList)
{
// We are playing a playlist, so get the next file from the playlist
TInt nextFile = iPlayListIdx+1;
if (nextFile<iPlayList->Count())
{
iPlayListIdx++;
file = (*iPlayList)[iPlayListIdx];
while (file->FileType() == TOggFile::EPlayList)
{
// Another playlist. Push the current playlist onto the stack and get the next file
TOggPlayListStackEntry playListStackEntry(iPlayList, iPlayListIdx);
TInt err = iPlayListStack.Push(playListStackEntry);
if (err != KErrNone)
{
iPlayListStack.Reset();
return KNullDesC;
}
iPlayList = (TOggPlayList*) file;
iPlayListIdx = 0;
file = (*iPlayList)[iPlayListIdx];
}
// Check that the file is still there (media hasn't been removed)
if (iOggPlayback->Info(*(file->iFileName), ETrue) == KErrOggFileNotFound)
iPlayingIdx = ENoFileSelected;
if (iPlayingIdx == ENoFileSelected)
return (KNullDesC);
return *(file->iFileName);
}
else
{
// End of current playlist, pop the previous playlist from the stack
TOggPlayListStackEntry playListStackEntry;
iPlayListStack.Pop(playListStackEntry);
iPlayList = playListStackEntry.iPlayList;
iPlayListIdx = playListStackEntry.iPlayingIdx;
while (iPlayList != NULL)
{
// Grab the next file if possible (else pop another playlist and try again)
TInt nextFile = iPlayListIdx+1;
if (nextFile<iPlayList->Count())
{
iPlayListIdx++;
file = (*iPlayList)[iPlayListIdx];
// If we have another play list, drop into it (as above)
while (file->FileType() == TOggFile::EPlayList)
{
TOggPlayListStackEntry playListStackEntry(iPlayList, iPlayListIdx);
TInt err = iPlayListStack.Push(playListStackEntry);
if (err != KErrNone)
{
iPlayListStack.Reset();
return KNullDesC;
}
iPlayList = (TOggPlayList*) file;
iPlayListIdx = 0;
file = (*iPlayList)[iPlayListIdx];
}
return *(file->iFileName);
}
TOggPlayListStackEntry playListStackEntry;
iPlayListStack.Pop(playListStackEntry);
iPlayList = playListStackEntry.iPlayList;
iPlayListIdx = playListStackEntry.iPlayingIdx;
}
}
}
if (iPlayingIdx+1<nSongs)
{
// We are in the middle of the song list. Now play the next song.
SetPlaying(iPlayingIdx+1);
}
else if (iRepeat)
{
// We are at the end of the song list, repeat it
SetPlaying(0);
}
else
{
// We are at the end of the playlist, stop here.
SetPlaying(ENoFileSelected);
}
if (iPlayingIdx == ENoFileSelected)
return (KNullDesC);
file = iFileList[iPlayingIdx];
if (file->FileType() == TOggFile::EPlayList)
file = (*iPlayList)[iPlayListIdx];
return *(file->iFileName);
}
const TDesC& COggNormalPlay::GetPreviousSong()
{
TInt nSongs= iFileList.Count();
if ( (iPlayingIdx == ENoFileSelected) || (nSongs <=0) )
{
SetPlaying(ENoFileSelected);
return(KNullDesC);
}
TOggFile* file = iFileList[iPlayingIdx];
if (file->FileType() == TOggFile::EPlayList)
{
// We are playing a playlist, so get the previous file from the playlist
TInt prevFile = iPlayListIdx-1;
if (prevFile>=0)
{
iPlayListIdx--;
file = (*iPlayList)[iPlayListIdx];
while (file->FileType() == TOggFile::EPlayList)
{
// Another playlist. Push the current playlist onto the stack and get the previous file
TOggPlayListStackEntry playListStackEntry(iPlayList, iPlayListIdx);
TInt err = iPlayListStack.Push(playListStackEntry);
if (err != KErrNone)
{
iPlayListStack.Reset();
return KNullDesC;
}
iPlayList = (TOggPlayList*) file;
iPlayListIdx = iPlayList->Count()-1;
file = (*iPlayList)[iPlayListIdx];
}
return *(file->iFileName);
}
else
{
// Beginning of current playlist, pop the previous playlist from the stack
TOggPlayListStackEntry playListStackEntry;
iPlayListStack.Pop(playListStackEntry);
iPlayList = playListStackEntry.iPlayList;
iPlayListIdx = playListStackEntry.iPlayingIdx;
while (iPlayList != NULL)
{
// Grab the previous file if possible (else pop another playlist and try again)
TInt prevFile = iPlayListIdx-1;
if (prevFile>=0)
{
iPlayListIdx--;
file = (*iPlayList)[iPlayListIdx];
// If we have another play list, drop into it (as above)
while (file->FileType() == TOggFile::EPlayList)
{
TOggPlayListStackEntry playListStackEntry(iPlayList, iPlayListIdx);
TInt err = iPlayListStack.Push(playListStackEntry);
if (err != KErrNone)
{
iPlayListStack.Reset();
return KNullDesC;
}
iPlayList = (TOggPlayList*) file;
iPlayListIdx = iPlayList->Count()-1;
file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -