Commit 77f52d97 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

libvlc_media_player_set_pause: race-free pause/resume function

While -confusingly IMHO- libvlc_media_player_pause() toggles the pause
state, libvlc_media_player_set_pause() sets it.
(cherry picked from commit 4faa38ecba8274d50fb03ff070ff18df9f4f9875)
parent 3e23e0bc
......@@ -176,6 +176,15 @@ VLC_PUBLIC_API int libvlc_media_player_is_playing ( libvlc_media_player_t *p_mi
*/
VLC_PUBLIC_API int libvlc_media_player_play ( libvlc_media_player_t *p_mi );
/**
* Pause or resume (no effect if there is no media)
*
* \param mp the Media Player
* \param do_pause play/resume if zero, pause if non-zero
*/
VLC_PUBLIC_API void libvlc_media_player_set_pause ( libvlc_media_player_t *mp,
int do_pause );
/**
* Toggle pause (no effect if there is no media)
*
......
......@@ -693,10 +693,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
return 0;
}
/**************************************************************************
* Pause.
**************************************************************************/
void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
void libvlc_media_player_set_pause( libvlc_media_player_t *p_mi, int paused )
{
input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi );
if( !p_input_thread )
......@@ -705,17 +702,34 @@ void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
libvlc_state_t state = libvlc_media_player_get_state( p_mi );
if( state == libvlc_Playing || state == libvlc_Buffering )
{
if( libvlc_media_player_can_pause( p_mi ) )
input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S );
else
libvlc_media_player_stop( p_mi );
if( paused )
{
if( libvlc_media_player_can_pause( p_mi ) )
input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S );
else
libvlc_media_player_stop( p_mi );
}
}
else
input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
{
if( !paused )
input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
}
vlc_object_release( p_input_thread );
}
/**************************************************************************
* Toggle pause.
**************************************************************************/
void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
{
libvlc_state_t state = libvlc_media_player_get_state( p_mi );
bool playing = (state == libvlc_Playing || state == libvlc_Buffering);
libvlc_media_player_set_pause( p_mi, playing );
}
/**************************************************************************
* Tells whether the media player is currently playing.
*
......
......@@ -129,6 +129,7 @@ libvlc_media_player_is_playing
libvlc_media_player_new
libvlc_media_player_new_from_media
libvlc_media_player_next_chapter
libvlc_media_player_set_pause
libvlc_media_player_pause
libvlc_media_player_play
libvlc_media_player_previous_chapter
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment