LiveMediaPlayer

API Reference: UI.LiveMediaPlayer

LiveMediaPlayer is a live streaming viewer based on NoMediaClient library. It is used for audio and video playback in RTMP/RTMPT/RTSP/HTTP/TCP/UDP/FILE format.

Original iOS library: https://github.com/NodeMedia/NodeMediaClient-iOS Original Android library: https://github.com/NodeMedia/NodeMediaClient-Android

TypeScript code blocks include examples of how to implement, override and components within the theme. You can create page with the UI Editor to make your page compatible with theming and then you can implement themable components programmatically. Once the page is created with the UI Editor, it generates a class under scripts/generated/pages. You can then extend that class with the following TypeScript classes.

LiveMediaPlayer Event Callback

You can listen the changes using onChange callback. Events are listed below.

LiveMediaPlayer Events

  • 1000: Connecting to video

  • 1001: Video connection successful

  • 1002: If the video connection fails, it will automatically reconnect.

  • 1003: The video starts to reconnect

  • 1004: End of the video playback

  • 1005: If the network is abnormal during video playback, it will automatically reconnect.

  • 1006: When the network connection times out, it will automatically reconnect.

  • 1100: The play buffer is empty.

  • 1101: The playback buffer is buffering data.

  • 1102: When the playback buffer reaches the bufferTime setting value, playback starts.

  • 1103: Received RTMP protocol stream EOF. It will automatically reconnect.

  • 1104: After decoding, the height and width of the video are obtained.

TypeScript
TypeScript
import PageSampleDesign from 'generated/pages/pageSample';
import FlexLayout = require('sf-core/ui/flexlayout');
import LiveMediaPlayer = require("sf-core/ui/livemediaplayer");
//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
myLiveMediaPlayer: LiveMediaPlayer;
constructor() {
super();
// Overrides super.onShow method
this.onShow = onShow.bind(this, this.onShow.bind(this));
// Overrides super.onLoad method
this.onLoad = onLoad.bind(this, this.onLoad.bind(this));
this.layout.flexDirection = FlexLayout.FlexDirection.ROW;
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
}
}
/**
* @event onShow
* This event is called when a page appears on the screen (everytime).
* @param {function} superOnShow super onShow function
* @param {Object} parameters passed from Router.go function
*/
function onShow(superOnShow: () => void) {
const { headerBar } = this;
superOnShow();
this.myLiveMediaPlayer.start();
}
/**
* @event onLoad
* This event is called once when page is created.
* @param {function} superOnLoad super onLoad function
*/
function onLoad(superOnLoad: () => void) {
superOnLoad();
this.myLiveMediaPlayer = new LiveMediaPlayer({
inputUrl: "https://tv-trt1.live.trt.com.tr/master_720.m3u8",
scaleType: LiveMediaPlayer.ScaleType.ASPECTFIT,
onChange: (params) => {
let { event, message } = params;
console.log("Event status code: " + event);
console.log("Message: " + message);
}
});
this.layout.addChild(this.myLiveMediaPlayer, "myLiveMediaPlayer", null, {
flexGrow: 1
});
}