Commit 4faa38ec 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.
parent 67e7a01a
...@@ -176,6 +176,15 @@ VLC_PUBLIC_API int libvlc_media_player_is_playing ( libvlc_media_player_t *p_mi ...@@ -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 ); 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) * Toggle pause (no effect if there is no media)
* *
......
...@@ -690,10 +690,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi ) ...@@ -690,10 +690,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
return 0; return 0;
} }
/************************************************************************** void libvlc_media_player_set_pause( libvlc_media_player_t *p_mi, int paused )
* Pause.
**************************************************************************/
void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
{ {
input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi ); input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi );
if( !p_input_thread ) if( !p_input_thread )
...@@ -702,17 +699,34 @@ void libvlc_media_player_pause( libvlc_media_player_t *p_mi ) ...@@ -702,17 +699,34 @@ void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
libvlc_state_t state = libvlc_media_player_get_state( p_mi ); libvlc_state_t state = libvlc_media_player_get_state( p_mi );
if( state == libvlc_Playing || state == libvlc_Buffering ) if( state == libvlc_Playing || state == libvlc_Buffering )
{ {
if( libvlc_media_player_can_pause( p_mi ) ) if( paused )
input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S ); {
else if( libvlc_media_player_can_pause( p_mi ) )
libvlc_media_player_stop( p_mi ); input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S );
else
libvlc_media_player_stop( p_mi );
}
} }
else 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 ); 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. * Tells whether the media player is currently playing.
* *
......
...@@ -129,6 +129,7 @@ libvlc_media_player_is_playing ...@@ -129,6 +129,7 @@ libvlc_media_player_is_playing
libvlc_media_player_new libvlc_media_player_new
libvlc_media_player_new_from_media libvlc_media_player_new_from_media
libvlc_media_player_next_chapter libvlc_media_player_next_chapter
libvlc_media_player_set_pause
libvlc_media_player_pause libvlc_media_player_pause
libvlc_media_player_play libvlc_media_player_play
libvlc_media_player_previous_chapter 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