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.

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
      }
      // ...
    };
    
  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:

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

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

    html_media_element->Play([](OperationResult result) {
      if (result != OperationResult::kSuccess) {
        // Handle errors
      }
    });
    
  • 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
      }
      // ...
    };