top

Multimedia

This topic describes how your application can play media content using the Tizen.Multimedia.Player class.

You can implement media playback functionality in your .NET application.

The Tizen.Multimedia.Player class provides the following features:

  • Operating general controls for the media content, such as play, pause, resume, and stop
    The player has events you can use to receive notifications of player status changes during playback. Since the player engine works asynchronously, you must implement event handlers to ensure that the player flows correctly. When any player operation is complete, the PlaybackCompleted event of the Tizen.Multimedia.Player class is raised. If an error occurs in the player engine, you can be notified through the ErrorOccurred event.
  • Getting information about the media content
    After the player state is changed to Ready, the multimedia resource is available and you can get content information from the media, such as by using the methods and properties of the Tizen.Multimedia.StreamInfo class. You can also get content information during the Playing state, in some streaming scenarios.

Prerequisites

To enable your application to play media from various sources, the application has to request permission by adding the following privileges to the "tizen-manifest.xml" file:

<privileges>
  <!-- To stream media from the network -->
  <privilege>http://tizen.org/privilege/internet</privilege>
  <!-- To play media from internal storage --> 
  <privilege>http://tizen.org/privilege/mediastorage</privilege>
  <!-- To play media from external storage --> 
  <privilege>http://tizen.org/privilege/externalstorage</privilege>
</privileges>

Playing a Video File

To play a video file:

  1. Create an instance of the Tizen.Multimedia.Player class:

    Player player = new Player();
    
  2. To receive notifications, add event handlers to the appropriate events of the Tizen.Multimedia.Player class:

    • To receive notifications when playback ends, register an event handler for the PlaybackCompleted event:
      player.PlaybackCompleted += (s, e) =>
      {
        //Do something when playback is completed
      };
      
    • To receive notifications about player errors during playback, register an event handler for the ErrorOccurred event:
      player.ErrorOccurred += (s, e) =>
      {
        //Do something when error has ocurred
      };
      
      The player error event is raised when the player stops working due to an error. You can use the event to try to recover from the error. For example, try to change the player state to Ready by calling the Stop() method, and then reset the player by calling the Unprepare() method.
  3. Specify the video source to play by creating an instance of the Tizen.Multimedia.MediaUriSource class with the path to the video file, and setting that as the Source property of the Tizen.Multimedia.Player class instance you want to play the file with:

    MediaUriSource mediaSource = new MediaUriSource(uri);
    player.SetSource(mediaSource);
    
    Note

    The default URI protocol is "file://". For HTTP or RSTP streaming, the URI must begin with "http://" or "rtsp://". If you provide an invalid URI, you are not notified of an error until the Start() method is called.

  4. Create and set the display on which the video is played, using the Display property of the Tizen.Multimedia.Player class:

    Display display = new Display(Forms.Context.MainWindow); 
    player.Display = display; 
    
  5. Prepare the player for playback using the PrepareAsync() method of the Tizen.Multimedia.Player class, then start playback:

    private async void preparePlayer()
    {
      await player.PrepareAsync();
    
      player.Start();
    }
    

    The PrepareAsync() method changes the player state from Idle to Ready, which is required to start playback, and the Start() method changes the player state from Ready to Playing. The video file plays until you call the Stop() or Pause() method.

  6. To stop and reset the player:
    a. Stop the player using the Stop() method:

    player.Stop();
    

    b. Reset the player using the Unprepare() method. The most recently used source is reset and no longer associated with the player:

    player.Unprepare();
    
  7. When you no longer need the player, release all resources allocated to the player instance using the Dispose() method:

    player.Dispose();
    player = null;