Example #1
0
void SjPlayer::SetMainVol(int newVol) // 0..255
{
	// This function may only be called from the main thread.
	wxASSERT( wxThread::IsMain() );

	if( newVol < 0 )   { newVol = 0;   }
	if( newVol > 255 ) { newVol = 255; }

	m_mainVol   = newVol;
	m_mainGain  = ((double)newVol)/255.0F;

	DoSetMainVol();
}
void SjPlayer::DoPlay(long ms, bool fadeToPlay) // press on play
{
	if( m_impl->m_currStream )
	{
		if( m_paused )
		{
			// just switch state from pause to play
			xine_set_param(m_impl->m_currStream->GetXineStream(), XINE_PARAM_SPEED, XINE_SPEED_NORMAL);
			m_paused = false;
		}
	}
	else
	{
		// if we're not playing, we're also not paused...
		m_paused = false;

		// open player and start the stream at the current position
		if( m_queue.GetCount()<=0 )
		{
			return; // don't log any error
		}

		if( !m_impl->InitXine() ) {
			return; // error
		}

		// open xine output ports (currently audio only)
		if( m_impl->m_ao_port == NULL ) {
			m_impl->m_ao_port = xine_open_audio_driver(m_impl->m_xine , static_cast<const char*>(m_impl->m_iniDevice.mb_str(wxConvUTF8)), NULL);
			if( m_impl->m_ao_port == NULL ) {
				wxLogError(wxT("Play()/xine_open_audio_driver() failed."));
				return;
			}
		}

		DoSetMainVol();

		// create a stream bound to the output
		long queuePos = m_queue.GetCurrPos();
		m_impl->m_currStream = new SjXineStream(m_impl, m_queue.GetUrlByPos(queuePos));
		if( !m_impl->m_currStream->XinePlay(ms) ) {
			wxLogError(wxT("DoPlay() failed."));

			// Xine stream is non-functional, don't touch
			delete m_impl->m_currStream;
			m_impl->m_currStream = NULL;
		}
	}
}