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
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.
The components in the example are added from the code for better showcase purposes. To learn more about the subject you can refer to:
Adding Component From CodeAs a best practice, Smartface recommends using the WYSIWYG editor in order to add components and styles to your page or library. To learn how to use UI Editor better, please refer to this documentation
UI Editor Basics- Page UI
- Page.ts
{
"components": [
{
"className": ".page",
"id": "df2a-1527-309d-ab7e",
"initialized": true,
"props": {
"children": [
"a668-8e81-434e-6681",
"95bf-507e-ec77-0a7a",
"5a00-8ca7-3153-0fbc",
"b55a-3417-25b5-1038",
"f594-152c-8a98-27bb"
],
"name": "pgLiveMediaPlayer",
"orientation": "PORTRAIT",
"parent": null
},
"type": "Page",
"userProps": {},
"version": "0.0.1.a"
},
{
"className": ".statusBar",
"id": "a668-8e81-434e-6681",
"props": {
"children": [],
"isRemovable": false,
"name": "statusBar",
"parent": "df2a-1527-309d-ab7e"
},
"type": "StatusBar",
"userProps": {}
},
{
"className": ".headerBar",
"id": "95bf-507e-ec77-0a7a",
"props": {
"children": [],
"isRemovable": false,
"name": "headerBar",
"parent": "df2a-1527-309d-ab7e",
"title": "LiveMediaPlayer"
},
"type": "HeaderBar",
"userProps": {
"title": "LiveMediaPlayer"
}
},
{
"className": ".flexLayout",
"id": "5a00-8ca7-3153-0fbc",
"oldName": "flexLayout1",
"props": {
"children": [],
"name": "flLiveMediaPlayer",
"parent": "df2a-1527-309d-ab7e",
"usePageVariable": true
},
"type": "FlexLayout",
"userProps": {
"usePageVariable": true
}
},
{
"className": ".button",
"id": "b55a-3417-25b5-1038",
"oldName": "button1",
"props": {
"children": [],
"name": "btnAction",
"parent": "df2a-1527-309d-ab7e",
"text": "Play",
"usePageVariable": true
},
"type": "Button",
"userProps": {
"text": "Play",
"usePageVariable": true
}
},
{
"className": ".button",
"id": "f594-152c-8a98-27bb",
"oldName": "btn",
"props": {
"children": [],
"name": "btnPause",
"parent": "df2a-1527-309d-ab7e",
"text": "Pause",
"usePageVariable": true
},
"type": "Button",
"userProps": {
"text": "Pause",
"usePageVariable": true
}
}
]
}
import PgLiveMediaPlayerDesign from "generated/pages/pgLiveMediaPlayer";
import { withDismissAndBackButton } from "@smartface/mixins";
import { Router, Route } from "@smartface/router";
import LiveMediaPlayer from "@smartface/native/ui/livemediaplayer";
import Color from "@smartface/native/ui/color";
import { ScaleType } from "@smartface/native/ui/livemediaplayer/livemediaplayer";
import { styleableComponentMixin } from "@smartface/styling-context";
class StyleableLiveMediaPlayer extends styleableComponentMixin(
LiveMediaPlayer
) {}
export default class pgLiveMediaPlayer extends withDismissAndBackButton(
PgLiveMediaPlayerDesign
) {
private liveMediaPlayer: StyleableLiveMediaPlayer;
private isPlaying = false;
constructor(private router?: Router, private route?: Route) {
super({});
this.btnAction.on("press", () => {
if (this.isPlaying) {
this.liveMediaPlayer?.stop();
this.btnAction.text = "Start";
this.isPlaying = false;
} else {
this.liveMediaPlayer?.start();
this.btnAction.text = "Stop";
this.isPlaying = true;
}
});
this.btnPause.on("press", () => {
if (this.isPlaying) {
this.liveMediaPlayer?.pause();
this.btnPause.text = "Resume";
this.isPlaying = false;
} else {
this.liveMediaPlayer?.start();
this.btnPause.text = "Pause";
this.isPlaying = true;
}
});
}
initLiveMediaPlayer() {
this.liveMediaPlayer = new StyleableLiveMediaPlayer({
flexGrow: 1,
inputUrl: "https://tv-trt1.medya.trt.com.tr/master_720.m3u8",
backgroundColor: Color.BLACK,
onChange: (params) => {
console.info(params.message, params);
},
scaleType: ScaleType.ASPECTFILL,
});
this.flLiveMediaPlayer.addChild(
this.liveMediaPlayer,
"liveMediaPlayer",
".grow-relative"
);
}
onShow() {
super.onShow();
this.initBackButton(this.router); //Addes a back button to the page headerbar.
}
onLoad() {
super.onLoad();
this.initLiveMediaPlayer();
}
}