mystone.cpp

来自「S60 3版 音乐播放器及进度条实现 功能:前后倒放歌曲及暂停等功能」· C++ 代码 · 共 240 行

CPP
240
字号
/*
============================================================================
Name        : MyStone.cpp
Author      : 
Version     :
Copyright   : Your copyright notice
Description : MyStone.cpp - source file
============================================================================
*/

#include "MyStone.h"
#include <aknlists.h>//for Listbox
#include <eikalign.h>
#include <aknutils.h>
#include <f32file.h>
#include "Symbian4AppUi.h"

CMyStone*  CMyStone::NewL()
{
	CMyStone* self = NewLC();
	CleanupStack::Pop();
	return self;
}

CMyStone* CMyStone::NewLC( )
{
	CMyStone* self= new (ELeave) CMyStone;
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}
CMyStone::CMyStone()
{
	iPlayer=NULL;
}

void CMyStone::ConstructL()
{
	CSymbian4AppUi* pApp = (CSymbian4AppUi*)CEikonEnv::Static()->AppUi();
	iArrayFlat = pApp->GetPlayListPoint(); 

	iIndex  = pApp->GetCurrent(); 
	//iVolume = pApp->iVolume;
}
CMyStone::~CMyStone()
{
	Stop();

}

void CMyStone::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
{
	if (aError==KErrNone)
	{
		SetMusicVolume(iVolume);
		iPlayer->Play();
		iState=EPlaying;
	}
	else
	{
		iPlayer->Stop();
		iState=ENone;
	}
}

void CMyStone::MapcPlayComplete(TInt aError)
{
	if (aError==KErrNone)
	{
		PLayMusic(iIndex);
	}
	else
	{
		iPlayer->Stop();
		iState=ENone;
	}
}


void CMyStone::Pause()
{
//	iPlayer->GetPosition(iLastPosition);
//	iPlayer->SetPosition(iLastPosition);
	iPlayer->Pause();
	iState=EPause;
}

void CMyStone::Stop()
{
	if (iPlayer)
	{
		iPlayer->Stop();
	}
	delete iPlayer;
	iPlayer=NULL;
	iState=ENone;
}

void CMyStone::PLayMusic(TInt aCurrent)
{
	if (iArrayFlat->Count()<1)
	{
		return;
	}
	else
	{
		HBufC*itemText=HBufC::NewL(512);
		TBuf<64> buftemp;
		_LIT(itemPath,"C:\\Data\\Sounds\\");
		itemText->Des().Append(itemPath);
		TPtrC16 ptr = iArrayFlat->MdcaPoint(aCurrent);
		buftemp.Copy(ptr.Mid(2));
		//buftemp.Copy((*iArrayFlat)[aCurrent].Mid(2));
		if(buftemp.Find(_L("\t")) != KErrNotFound)
			buftemp.TrimLeft();
		itemText->Des().Append(buftemp);	
		if (iState == ENone || iState == EStopped)
		{
			if (iPlayer != NULL)
			{
				iPlayer->Stop();
				delete iPlayer;
				iPlayer = NULL;

			}

			iPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(*itemText/*KToPlayFileWav*/ ,
				*this);//, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality);
			iState = EPlaying;
		}
		if(iState = EPause)
		{
		//	iPlayer->SetPosition(iLastPosition);
			iPlayer->Play();
			iState = EPlaying;
		}
		delete itemText;
		itemText = NULL;

		buftemp.Zero();

	}

	//iPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(_L("complicated.mp3")/*KToPlayFileWav*/ ,
	//			*this);
	// iPlayer->Play();

}

void CMyStone::SetMusicVolume(TInt aVolume)
{

}



void  CMyStone::Time(TDes& aTime,TDes& afirst)
{

	//////////////////////////////////
	TTimeIntervalMicroSeconds time; 
	time = iPlayer->Duration(); 
    //////////////////////
	ilength = time.Int64();
    ///////////////////////
/*	TInt64 time1 = time.Int64();	
	 TInt t1 = time1/1000000;  
	aTime.Zero();
	aTime.AppendFormat(_L("02%d:02%d"),t1/60,t1%60);
	*/
	TInt64 time1 = time.Int64();	
	 time1 = time1/1000000;  

	TInt min = (time1%3600)/60;
	TInt sec = (time1%3600%60);
	aTime.Zero();
	if(min<10)
	{
		aTime.Append(_L("0"));
		aTime.AppendNum(min);
	}
	else
	{
		aTime.AppendNum(min);
	}
	aTime.Append(_L(":"));
	if (sec<10)
	{
		aTime.Append(_L("0"));
		aTime.AppendNum(sec);
	}
	else
	{  
		aTime.AppendNum(sec);
	}
	
	//////////////////////////////
	TTimeIntervalMicroSeconds firsttime;
	iPlayer->GetPosition(firsttime);
    ///////////////////////////
	islow=firsttime.Int64();
    ////////////////////////////
  	TInt64 time2 = firsttime.Int64();  
	TInt t = time2/1000000;  
	afirst.Zero();
	afirst.AppendFormat(_L("%02d:%02d"),t/60,t%60);
	/*TInt min2 = (time2%3600)/60;
	TInt sec2 = (time2%3600%60);
	afirst.Zero();
	if(min2<10)
	{
		afirst.Append(_L("0"));
		afirst.AppendNum(min2);
	}
	else
	{
		afirst.AppendNum(min2);
	}
	afirst.Append(_L(":"));
   if (sec2<10)
    {
		afirst.Append(_L("0"));
		afirst.Append(sec2);
    }
	else
	{
	    afirst.AppendNum(sec2);
	}*/
}

TInt64 CMyStone::GetNum()
{
	return islow;
}

TInt64 CMyStone::GetLength()
{
	return ilength;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?