X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=test%2Flibvlc%2Fmedia_player.c;h=53ba3d6ba4a28b7a8e017ca2f2494e76457230c0;hb=62cc24a877ad0e898cd173fbc75956ef217b9488;hp=a14a038825b0e806d425ede0aab524c454101abe;hpb=55c960749e8f91763e720ac610d5dd56f90fcde1;p=vlc diff --git a/test/libvlc/media_player.c b/test/libvlc/media_player.c index a14a038825..53ba3d6ba4 100644 --- a/test/libvlc/media_player.c +++ b/test/libvlc/media_player.c @@ -23,6 +23,47 @@ #include "test.h" +static void wait_playing(libvlc_media_player_t *mp) +{ + libvlc_state_t state; + do { + state = libvlc_media_player_get_state (mp); + } while(state != libvlc_Playing && + state != libvlc_Error && + state != libvlc_Ended ); + + state = libvlc_media_player_get_state (mp); + assert(state == libvlc_Playing || state == libvlc_Ended); +} + +static void test_media_player_set_media(const char** argv, int argc) +{ + const char * file = test_default_sample; + + log ("Testing set_media\n"); + + libvlc_instance_t *vlc = libvlc_new (argc, argv); + assert (vlc != NULL); + + libvlc_media_t *md = libvlc_media_new_path (vlc, file); + assert (md != NULL); + + libvlc_media_player_t *mp = libvlc_media_player_new (vlc); + assert (mp != NULL); + + libvlc_media_player_set_media (mp, md); + + libvlc_media_release (md); + + libvlc_media_player_play (mp); + + wait_playing (mp); + + libvlc_media_player_stop (mp); + libvlc_media_player_release (mp); + libvlc_release (vlc); +} + static void test_media_player_play_stop(const char** argv, int argc) { libvlc_instance_t *vlc; @@ -32,40 +73,24 @@ static void test_media_player_play_stop(const char** argv, int argc) log ("Testing play and pause of %s\n", file); - libvlc_exception_init (&ex); - vlc = libvlc_new (argc, argv, &ex); - catch (); + vlc = libvlc_new (argc, argv); + assert (vlc != NULL); - md = libvlc_media_new (vlc, file, &ex); - catch (); + md = libvlc_media_new_path (vlc, file); + assert (md != NULL); - mi = libvlc_media_player_new_from_media (md, &ex); - catch (); + mi = libvlc_media_player_new_from_media (md); + assert (mi != NULL); libvlc_media_release (md); - libvlc_media_player_play (mi, &ex); - catch (); - - /* Wait a correct state */ - libvlc_state_t state; - do { - state = libvlc_media_player_get_state (mi, &ex); - catch (); - } while( state != libvlc_Playing && - state != libvlc_Error && - state != libvlc_Ended ); - - assert( state == libvlc_Playing || state == libvlc_Ended ); + libvlc_media_player_play (mi); - libvlc_media_player_stop (mi, &ex); - catch (); + wait_playing (mi); + libvlc_media_player_stop (mi); libvlc_media_player_release (mi); - catch (); - libvlc_release (vlc); - catch (); } static void test_media_player_pause_stop(const char** argv, int argc) @@ -77,62 +102,36 @@ static void test_media_player_pause_stop(const char** argv, int argc) log ("Testing pause and stop of %s\n", file); - libvlc_exception_init (&ex); - vlc = libvlc_new (argc, argv, &ex); - catch (); + vlc = libvlc_new (argc, argv); + assert (vlc != NULL); - md = libvlc_media_new (vlc, file, &ex); - catch (); + md = libvlc_media_new_path (vlc, file); + assert (md != NULL); - mi = libvlc_media_player_new_from_media (md, &ex); - catch (); + mi = libvlc_media_player_new_from_media (md); + assert (mi != NULL); libvlc_media_release (md); - libvlc_media_player_play (mi, &ex); - catch (); + libvlc_media_player_play (mi); log ("Waiting for playing\n"); - /* Wait a correct state */ - libvlc_state_t state; - do { - state = libvlc_media_player_get_state (mi, &ex); - catch (); - } while( state != libvlc_Playing && - state != libvlc_Error && - state != libvlc_Ended ); - - assert( state == libvlc_Playing || state == libvlc_Ended ); + wait_playing (mi); #if 0 /* This can't work because under some condition (short file, this is the case) this will be * equivalent to a play() */ - libvlc_media_player_pause (mi, &ex); - catch(); + libvlc_media_player_pause (mi); log ("Waiting for pause\n"); - /* Wait a correct state */ - do { - state = libvlc_media_player_get_state (mi, &ex); - catch (); - } while( state != libvlc_Paused && - state != libvlc_Error && - state != libvlc_Ended ); - - assert( state == libvlc_Paused || state == libvlc_Ended ); - catch(); + wait_paused (mp); #endif - - libvlc_media_player_stop (mi, &ex); - catch (); + libvlc_media_player_stop (mi); libvlc_media_player_release (mi); - catch (); - libvlc_release (vlc); - catch (); } @@ -140,6 +139,7 @@ int main (void) { test_init(); + test_media_player_set_media (test_defaults_args, test_defaults_nargs); test_media_player_play_stop (test_defaults_args, test_defaults_nargs); test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);