chxavplayer.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,374 行 · 第 1/3 页
CPP
1,374 行
* ----
* Stop the playback. From user command.
*
*/
void
CHXAvPlayer::Stop()
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::Stop()\n"));
// prevent automatic playlist/loop advance after user request to stop
m_bEnableAutoPlayNext = false;
DoStopImp();
}
/*
* DoStopImp
* ------
* Stop
*
*/
void
CHXAvPlayer::DoStopImp()
{
m_clipPos = 0;
m_startupStage = ssStopped;
m_playerState.OnStop();
HX_ASSERT(m_hxPlayer);
m_hxPlayer->Stop();
}
/*
* Pause
* -----
*
*/
void
CHXAvPlayer::Pause()
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::Pause()\n"));
if ((m_hxPlayer != NULL) && (!m_hxPlayer->IsDone()))
{
m_hxPlayer->Pause();
m_playerState.OnPause();
}
}
/*
* Resume
* ------
*
*/
void
CHXAvPlayer::Resume()
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::Resume()\n"));
if ((m_hxPlayer != NULL) && (!m_hxPlayer->IsDone()))
{
m_hxPlayer->Begin();
}
}
/*
* SetVolume
* ---------
*
*/
void
CHXAvPlayer::SetVolume(TUint level)
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::SetVolume(): level = %d\n", level));
HX_ASSERT(level <= 100);
HX_ASSERT(m_audioPlayer);
if( level <= 100 )
{
if(m_audioPlayer)
{
IHXVolume* pVolume = m_audioPlayer->GetDeviceVolume();
if( pVolume )
{
pVolume->SetVolume(level);
HX_RELEASE(pVolume);
}
}
m_playerState.OnVolume(level);
}
}
void
CHXAvPlayer::StepVolume(TInt factor)
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::StepVolume(): fact = %d\n", factor));
// adjust volume by factor
TInt level = GetVolume();
level += m_volumeStep * factor;
// constrain to valid level
level = min(kVolumeMax, max(0, level));
SetVolume(level);
}
/*
* GetVolume
* ---------
*
*/
TUint
CHXAvPlayer::GetVolume() const
{
TUint level = 0;
HX_ASSERT(m_audioPlayer);
if (m_audioPlayer)
{
IHXVolume* pVolume = m_audioPlayer->GetDeviceVolume();
if( pVolume )
{
level = pVolume->GetVolume();
HX_RELEASE(pVolume);
}
}
return level;
}
/*
* Mute
* ----
*
*/
void
CHXAvPlayer::Mute(bool bToMute)
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::Mute('%s')\n", dbg::Bool(bToMute)));
HX_ASSERT(m_audioPlayer);
if (m_audioPlayer)
{
IHXVolume* pVolume = m_audioPlayer->GetDeviceVolume();
if( pVolume )
{
pVolume->SetMute( bToMute );
HX_RELEASE(pVolume);
}
}
m_playerState.OnMute(bToMute);
}
/*
* IsMuted
* -------
*
*/
bool
CHXAvPlayer::IsMuted() const
{
bool bMute = false;
HX_ASSERT(m_audioPlayer);
if (m_audioPlayer)
{
IHXVolume* pVolume = m_audioPlayer->GetDeviceVolume();
if( pVolume )
{
bMute = pVolume->GetMute();
HX_RELEASE(pVolume);
}
}
return bMute;
}
/*
* InitPlayerL
* -----------
*
* Create a new player object and set it up for playback. Call
* only when player is currently shutdown.
*
*/
void CHXAvPlayer::InitPlayerL(CCoeControl* pRenderWindow)
{
// player
HX_ASSERT(!m_hxPlayer);
m_spEngine->GetEngine()->CreatePlayer(m_hxPlayer.AsRef());
// site supplier (must be done before we setup client context)
m_siteSupplier = new (ELeave) CHXAvSiteSupplier();
m_siteSupplier->ConstructL(m_hxPlayer, pRenderWindow);
m_hxPlayer->SetClientContext(static_cast<IHXClientAdviseSink*>(this)); // arbitrary unknown
// set us up to observe player events
m_hxPlayer->AddAdviseSink(this);
// set us up to observer error messages
comptr<IHXErrorSinkControl> control;
control.From(m_hxPlayer);
control->AddErrorSink(this, HXLOG_EMERG, HXLOG_INFO);
// set us up as ap selector
m_apManager.From(m_hxPlayer);
if(m_apManager)
{
m_apManager->RegisterSelector(this);
}
// grab some interfaces
m_audioPlayer.From(m_hxPlayer);
// set up to receive group/track events
comptr<IHXGroupManager> groupMgr;
groupMgr.From(m_hxPlayer);
if(groupMgr)
{
groupMgr->AddSink(this);
}
}
// IHXAccessPointSelector
STDMETHODIMP
CHXAvPlayer::SelectAccessPoint(IHXAccessPointSelectorResponse* pResponse)
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::SelectAccessPoint()\n"));
HX_RESULT hr = HXR_OK;
if(m_apSelector)
{
HX_ASSERT(m_apManager);
TRAPD(err, hr = m_apSelector->DoSelectAccessPointL(m_apManager, pResponse));
if(err != KErrNone)
{
hr = HXR_FAIL;
}
}
if(SUCCEEDED(hr))
{
// just in case; we should detect this via other methods
OnNetConnect();
}
else
{
// some pending client core tasks (e.g., group sink notifications) get processed
// before this error is detected and reported; we want to ignore these, hence this
// pulchritudinous flag
m_bAccessPointSetupFailed = true;
}
return hr;
}
/*
* ShutDown
* --------
*
* Release and destroy the player object. The player does not unload
* renderers and sites until it closes or a new presentation is opened.
*
* UI owner must call this to free references held by client core (so that
* subsequent release of this object results in deletion)
*
* Undoes everything done in InitPlayerL
*
* Note: clip, playlist and header info remains valid
*/
void
CHXAvPlayer::ShutDown()
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::ShutDown()\n"));
//HX_ASSERT(m_hxPlayer);
if( m_hxPlayer )
{
// stop and remove sinks (just in case; probably not really necessary)
if(!m_hxPlayer->IsDone())
{
m_hxPlayer->Stop();
}
m_hxPlayer->RemoveAdviseSink(this);
comptr<IHXErrorSinkControl> control;
control.From(m_hxPlayer);
control->RemoveErrorSink(this);
control.Reset();
comptr<IHXGroupManager> groupMgr;
groupMgr.From(m_hxPlayer);
if(groupMgr)
{
groupMgr->RemoveSink(this);
}
// unregister with access point manager
if(m_apManager)
{
m_apManager->UnregisterSelector(this);
}
m_spEngine->GetEngine()->ClosePlayer(m_hxPlayer);
m_audioPlayer = 0;
m_siteSupplier = 0;
m_hxPlayer = 0;
m_apManager = 0;
}
// reset stuff associated with previously active HX player
m_mainUrl = "";
m_playUrl = "";
m_pPlaylist = 0;
m_pPlayItr = 0;
m_bIsTruePlaylistLoaded = false;
ResetUnloadedClipState();
}
/*
* GetClipTime
* -----------
* Returns the point in the timeline where we are currently.
*
*/
ULONG32
CHXAvPlayer::GetClipTime() const
{
// note: we don't use IHXPlayer::GetCurrentPlayTime() so we have better control over this value
return m_clipPos;
}
/*
* EndSeek
* -------
* Called when user stops seeking
*
*/
void
CHXAvPlayer::EndSeek()
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::EndSeek()\n"));
HX_ASSERT(m_hxPlayer);
if( m_clipPos >= GetClipDuration() )
{
// seek to end
DoStopImp();
}
else
{
HX_RESULT hr = m_hxPlayer->Seek(m_clipPos);
if( SUCCEEDED(hr) )
{
// auto-resume playback if we were playing when we began seeking
if (m_bResumeOnEndSeek)
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::EndSeek(): resuming...\n"));
hr = m_hxPlayer->Begin();
}
else
{
m_playerState.OnPause();
}
}
if(FAILED(hr))
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::EndSeek(): failed to resume player after seek ('%s')\n", dbg::ErrorCode(hr)));
DoStopImp();
}
}
m_bResumeOnEndSeek = false;
}
/*
* StartSeek
* ---------
* Called when user begins seeking (drags slider, presses seek button, etc.)
*
*/
void
CHXAvPlayer::StartSeek()
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::StartSeek()\n"));
bool bIsPaused = (m_playerState.GetState() == CHXAvPlayerState::Paused);
m_bResumeOnEndSeek = !bIsPaused;
m_playerState.OnBeginSeek();
// we must pause while user is seeking
if( !bIsPaused )
{
m_hxPlayer->Pause();
}
}
/*
* SetSeekPoint
* ------------
* update current seek point as user moves slider/position around
*
*/
void
CHXAvPlayer::SetSeekPoint(ULONG32 time)
{
DPRINTF(SYMP_INFO, ("CHXAvPlayer::SetSeekPoint(): time = %lu\n", time));
HX_ASSERT(IsSeeking());
ULONG32 duration = GetClipDuration();
if( time > duration )
{
//
// set time to duration so when we attempt to resume
// we will automatically go on to the next clip
//
time = duration;
}
m_clipPos = time;
m_playerState.OnNewPos(time);
}
//IHXClientAdviseSink
STDMETHODIMP
CHXAvPlayer::OnPosLength(UINT32 ulPosition, UINT32 ulLength)
{
//DPRINTF(SYMP_INFO, ("CHXAvPlayer::OnPosLength(): pos = %lu\n", ulPosition));
if(ulPosition > 0)
{
// we assume we get a buffer message before OnPosLength() in every case
HX_ASSERT(m_startupStage >= ssPastFirstBuffer);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?