Difference between revisions of "LibVLC Media List Management"

From VideoLAN Wiki
Jump to navigation Jump to search
(→‎Sample Code: media_instance->media_player)
m (+{{Lowercase}}, +{{Example code}}, syntaxhighlight)
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{Lowercase}}
 +
{{Example code}}
 
== Global Description of the available objects ==
 
== Global Description of the available objects ==
The atomic item that represent a media that you can play is a '''media_descriptor''' in LibVLC.
+
The atomic item that represent a media that you can play is a '''libvlc_media''' in [[libVLC]].
  
A '''media_list''' is an object that contains several ''media_descriptor''. You can add items to that media_list.
+
A '''media_list''' is an object that contains several ''libvlc_media''. You can add items to that media_list.
 
 
A '''media_list_view''' is an object that provide a way to see/browse a media_list ('''Read-only'''). There are currently two kind of media_list_view:
 
* a '''flat''' media list view
 
* a '''hierarchical''' media list view
 
  
 
You can play a media_list using a '''media_list_player'''.
 
You can play a media_list using a '''media_list_player'''.
  
 
== A media descriptor can contain a media list ==
 
== A media descriptor can contain a media list ==
A playlist downloaded from Google video has a corresponding media_descriptor. This media_descriptor has several subitems. You can access them through libvlc_media_descriptor_subitems() which returns a media_list.
+
A playlist downloaded from Google video has a corresponding ''libvlc_media''. This ''libvlc_media'' has several subitems. You can access them through libvlc_media_subitems() which returns a media_list.
  
  
Line 17: Line 15:
  
 
== Sample Code ==
 
== Sample Code ==
 +
<syntaxhighlight lang="c">
 +
void play_media(libvlc_instance_t *vlc, libvlc_drawable_t window)
 +
{
  
void setup_media_list( libvlc_instance_t * p_vlc, libvlc_drawable_t window )
+
     libvlc_media_list_t *ml;
{
+
     libvlc_media_list_player_t *mlp;
    libvlc_exception_t e;
+
     libvlc_media_player_t *mp;
     libvlc_media_list_t * p_ml;
+
     libvlc_media_t *md1, *md2;
     libvlc_media_list_player_t * p_mlp;
 
     libvlc_media_player_t * p_mp;
 
     libvlc_media_descriptor_t * p_md1, *p_md2;
 
 
    
 
    
     libvlc_exception_init( &e );
+
     ml = libvlc_media_list_new(vlc);
 
 
    p_ml = libvlc_media_list_new( p_vlc, &e );
 
    quit_on_exception( &e );
 
 
      
 
      
     p_md1  = libvlc_media_descriptor_new( p_vlc, "http://mycool.com/movie1.avi", &e );
+
     md1 = libvlc_media_new_path(vlc, "http://mycool.com/movie1.avi");
     quit_on_exception( &e );
+
     md2 = libvlc_media_new_path(vlc, "http://mycool.com/movie2.avi");
 
    
 
    
     p_md2  = libvlc_media_descriptor_new( p_vlc, "http://mycool.com/movie2.avi", &e );
+
     libvlc_media_list_add_media(ml, md1);
     quit_on_exception( &e );
+
     libvlc_media_list_add_media(ml, md2);
 
    
 
    
     libvlc_media_list_add( p_ml, p_md1, &e );
+
     libvlc_media_release(md1);
     quit_on_exception( &e );
+
     libvlc_media_release(md2);
 
    
 
    
     libvlc_media_list_add( p_ml, p_md2, &e );
+
     mlp = libvlc_media_list_player_new(vlc);
    quit_on_exception( &e );
 
 
    
 
    
     libvlc_media_descriptor_release( p_md1 );
+
     mp = libvlc_media_player_new(vlc);
    libvlc_media_descriptor_release( p_md2 );
 
 
 
    p_mlp = libvlc_media_list_player_new( p_vlc, &e );
 
    quit_on_exception( &e );
 
 
 
    p_mp = libvlc_media_player_new( p_vlc, &e );
 
    quit_on_exception( &e );
 
 
    
 
    
 
     /* Use our media list */
 
     /* Use our media list */
     libvlc_media_list_player_set_media_list( p_mlp, p_ml, &e );
+
     libvlc_media_list_player_set_media_list(mlp, ml);
    quit_on_exception( &e );
+
 
 
+
     /* Use a given media player */
     /* Use a given media instance */
+
     libvlc_media_list_player_set_media_player(mlp, p_mp);
     libvlc_media_list_player_set_media_player( p_mlp, p_mp, &e );
 
    quit_on_exception( &e );
 
 
    
 
    
 
     /* Get our media instance to use our window */
 
     /* Get our media instance to use our window */
     libvlc_media_instance_set_drawable( p_mlp, window, &e );
+
     libvlc_media_player_set_drawable(mlp, window);
    quit_on_exception( &e );
 
 
    
 
    
 
     /* Play */
 
     /* Play */
     libvlc_media_instance_play( p_mlp, &e );
+
     libvlc_media_list_player_play(mlp);
    quit_on_exception( &e );
 
 
    
 
    
 
     /* Let it play forever */
 
     /* Let it play forever */
 
     while(1) sleep(300);
 
     while(1) sleep(300);
 
  }
 
  }
 +
</syntaxhighlight>
 +
 +
[[Category:libVLC]]

Latest revision as of 08:14, 4 March 2019

This page contains example code.

Global Description of the available objects

The atomic item that represent a media that you can play is a libvlc_media in libVLC.

A media_list is an object that contains several libvlc_media. You can add items to that media_list.

You can play a media_list using a media_list_player.

A media descriptor can contain a media list

A playlist downloaded from Google video has a corresponding libvlc_media. This libvlc_media has several subitems. You can access them through libvlc_media_subitems() which returns a media_list.


This explains how a media_list can be hierarchical. To browse it you'll use libvlc_media_list_hierarchy_view(). To view the all the item without hierarchy use libvlc_media_list_flat_view().

Sample Code

 void play_media(libvlc_instance_t *vlc, libvlc_drawable_t window)
 {

     libvlc_media_list_t *ml;
     libvlc_media_list_player_t *mlp;
     libvlc_media_player_t *mp;
     libvlc_media_t *md1, *md2;
  
     ml = libvlc_media_list_new(vlc);
    
     md1 = libvlc_media_new_path(vlc, "http://mycool.com/movie1.avi");
     md2 = libvlc_media_new_path(vlc, "http://mycool.com/movie2.avi");
  
     libvlc_media_list_add_media(ml, md1);
     libvlc_media_list_add_media(ml, md2);
  
     libvlc_media_release(md1);
     libvlc_media_release(md2);
  
     mlp = libvlc_media_list_player_new(vlc);
  
     mp = libvlc_media_player_new(vlc);
  
     /* Use our media list */
     libvlc_media_list_player_set_media_list(mlp, ml);

     /* Use a given media player */
     libvlc_media_list_player_set_media_player(mlp, p_mp);
  
     /* Get our media instance to use our window */
     libvlc_media_player_set_drawable(mlp, window);
  
     /* Play */
     libvlc_media_list_player_play(mlp);
  
     /* Let it play forever */
     while(1) sleep(300);
 }