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 4faa38ec)
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 )
......@@ -704,18 +701,35 @@ 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( 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
{
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