Starting Playback

This topic covers how to start media playback in Tizen WASM Player.

The process of starting playback differs between the different WASM Player latency modes.

Normal Latency Mode

Normal latency playback in the WASM Player is meant for VOD scenarios. In this mode, the platform's Media Player buffers Elementary Media Packet data sent by the application and ensures it plays smoothly.

Once ElementaryMediaStreamSource enters ReadyState::kOpen (thus opening ElementaryMediaTrack), the application can start buffering media data. In normal latency mode, several packets need to be buffered and processed by the platform before the playback can be started. The application must either observe HTMLMediaElement events (HTMLMediaElementListener::OnCanPlay()) to detect this moment or use the HTMLMediaElement autoplay feature.

Important

In normal latency mode, the opening and closing of ElementaryMediaStreamSource and ElementaryMediaTrack objects are not in sync with HTMLMediaElementListener::OnCanPlay(). The WASM Player objects open when the platform is ready to receive media data, and leave the Open state when packets cannot be received anymore. Elementary Media Packets that are sent affect both the ready state and events emitted by HTMLMediaElement, depending on the platform's internal media data buffer level. Therefore, the application must observe HTMLMediaElement through HTMLMediaElementListener for the complete Media Player state.

To start playback in normal latency mode:

  1. Configure Media Player as described in Initializing Media Player to Work With the WASM Player.

  2. The source enters ReadyState::kOpen and each track emits an ElementaryMediaTrackListener::OnTrackOpen() event to notify that it can accept elementary media data.

    class MyTrackListener : public samsung::wasm::ElementaryMediaTrackListener {
      // ...
      void OnTrackOpen() override {
        // Start the application's packet sending mechanism for the associated track
      }
      // ...
    };
    
    Note

    Alternatively, the application can wait for an ElementaryMediaStreamSourceListener::OnSourceOpen() event emitted by the source itself. OnTrackOpen events are generated before OnSourceOpen, so it's safe to trigger the packet sending mechanism in this event handler too.

    Important

    OnTrackOpen and OnSourceOpen events are generated whenever a track opens: starting playback after initialization is the most prominent case, but they also trigger, for example, during a Seek operation when the application is multitasking. No matter the reason, the first packet sent to a newly opened ElementaryMediaTrack must be a keyframe.

  3. Build up the internal Media Player data buffer by sending several packets. This is basically the same mechanism as described below in Sending Elementary Media Packets.

  4. When HTMLMediaElement is ready to start playback, it emits an HTMLMediaElementListener::OnCanPlay() event. Handle the event and call HTMLMediaElement::Play().

    class MyMediaElementListener : public samsung::html::HTMLMediaElementListener {
      // ...
      void OnCanPlay() override {
        html_media_element->Play([](OperationResult result) {
          if (result != OperationResult::kSuccess) {
            // Handle error
          }
        });
      }
      // ...
    };
    

For information regarding sending media data to Medial Player, see Sending Elementary Media Packets.

Low Latency Mode

Low latency playback in the WASM Player is meant for live streaming scenarios. In this mode the platform renders Elementary Media Packets immediately after the application sends them. Therefore it is up to the application to maintain the pipeline clock and stream synchronization.

In low latency modes, no buffering is required to start media playback. Media Player is ready to start playback at any moment, however WASM Player can accept packets only when HTMLMediaElement is in the Playing state.

When ElementaryMediaStreamSource::Open() is called, ElementaryMediaStreamSource is immediately set in the ReadyState::kOpenPending state. Once the application calls HTMLMediaElement::Play(), the source enters ReadyState::kOpen state and the ElementaryMediaTrack objects open. From that point on, Elementary Media Packets are accepted and rendered immediately.

To start playback in low latency modes:

  1. Configure Media Player as described in Initializing Media Player to Work With the WASM Player.

  2. When the application is ready to start playback, call HTMLMediaElement::Play():

    html_media_element->Play([](OperationResult result) {
      if (result != OperationResult::kSuccess) {
        // Handle errors
      }
    });
    
  3. The source enters ReadyState::kOpen and each track emits ElementaryMediaTrackListener::OnTrackOpen() event to notify it can accept elementary media data.

    class MyTrackListener : public samsung::wasm::ElementaryMediaTrackListener {
      // ...
      void OnTrackOpen() override {
        // Start the application's packet sending mechanism for the associated track
      }
      // ...
    };
    
    Note

    Alternatively, the application can wait for an ElementaryMediaStreamSourceListener::OnSourceOpen() event emitted by the source itself. OnTrackOpen events are generated before OnSourceOpen, so it's safe to trigger packet sending mechanism in this event handler too.

    Important

    OnTrackOpen and OnSourceOpen events are generated whenever a track opens: starting playback after initialization is the most prominent case, but both also trigger, for example, when playback is paused and then unpaused, or the application is multitasking. No matter the reason, the first packet sent to a newly opened ElementaryMediaTrack must be a keyframe.