Professional Documents
Culture Documents
Samsung Smart TV
1. 2.
Overview................................................................................................................................... 4 Introduction ................................................................................................................................ 5 2.1 Development environment .......................................................................................................... 5 2.2 How to Setup Flash Media Server .................................................................................................. 5 2.3 Files needed for a Flash Player App ................................................................................................ 6
3.
Overall structure .......................................................................................................................... 7 3.1 The Apps design ..................................................................................................................... 7 App project components description ................................................................................................... 7 3.2 App project directory structure ...................................................................................................... 8
4.
App Creation .............................................................................................................................. 9 4.1 Stage 1 - Creating the Basic App ................................................................................................... 9 4.2 Stage 2 - Creating the Flash Player Applet ....................................................................................... 15 4.3 Stage 3 Accessing Flash Player from the JavaScript .......................................................................... 21
5.
Preface
Purpose of Document
This document is a tutorial that is aimed at App developers for Samsung Smart TV, and is written to help developers understand how to use the Adobe Flash Player features of the Samsung App service. These features are needed to create VOD (Video on Demand) Apps based on RTMP and RTMPe protocols. It is recommended that you read Development Guide for Samsung Smart TV (hereinafter referred to as "the Guide") first. This document provides references to the Guide tutorial for your understanding.
Target Readers
This document is aimed at programmers who have used web development languages such as HTML, CSS, JavaScript and ActionScript, and will be even more helpful for those who have web development experience. This document has been written on the assumption that readers have already read the Guide tutorial.
1. Overview
This tutorial will go step by step through the development of a App that features video playback over the RTMP and RTMPe protocols. The main goal for this tutorial is to present basic ideas in clear and possibly simple way. It focuses on providing basic code that needs to take place in any App application that uses Adobe Flash Player as well as brief description of using streaming media over the RTMP/RTMPe protocols. The FMS (Flash Media Server) installation and configuration wont be discussed in here. Its been assumed that the complete environment have been set up and only the FMS instance address and video media file name need to be provided. At the time of writing the Samsung Smart TV engine is supporting version 8 of the Adobe Flash Player. The player however has been extended with RTMP and RTMPe as well as with h.264 video codec. The RTMPe implementation with its streaming data encryption capability is especially interesting since it enables Content Providers to build VOD applications.
2. Introduction
In order to develop the Adobe Flash Player App, developers are required to have background knowledge such as HTML, JavaScript, ActionScript and CSS. In general, there will be no explanation about HTML, JavaScript, ActionScript or CSS provided in this document. However some aspects including cooperation between JavaScript and ActionScript will be discussed as they are crucial for good understanding of the idea. Developing Apps suited for TVs is different from developing Apps on PCs in several aspects. You can get more information on this from the Guide.
In order to develop a Flash VoD App with RTMP(RTMPE), you need to have Adobe Flash Media Server, which can provide progressive download services and streaming services with RTMP(RTMPE) for Flash Player. Especially, RTMPE is the encrypted RTMP protocol for securing the stream data between clients and a server. For more details of Flash Media Server, please visite the Adobe website (http://www.adobe.com).
1.
How to download Adobe Flash Media Server You can download a trial copy of Adobe Flash Media Server from the Adobe website (http://www.adobe.com/downloads/). If you have an Adobe membership, its free, you can have access to trial downloads and special community areas.
2.
How to install Adobe Flash Media Server To install and get started Adobe Flash Media Server, you can use the online documentation, Adobe Flash Media Server Installation Guide. This manual explains information about system requirements, installing, upgrading, getting started streaming media and so on. see
http://www.adobe.com/livedocs/flashmediaserver/3.0/docs/help.html?content=08_xmlref_031.html.
3. Overall structure
In this section, were going to examine the structure of the App that we will create.
ActionScript based application: a. b. RTMP_Playback.swf file - generated by the Flash application and played by Flash Player. RTMP_Playback.fla file contains ActionScript code to control the playback.
Description
Object handling all playback related functions Object handling auxiliary functions Remote control key codes wrapper class Widget API class, in this tutorial we will use Player plugin functions
Directory
RTMP_Playback_Sample
Description
The main folder of the App. It contains the index.html, config.xml and RTMP_Playback fla and swf files.
Parent directory for all the Apps subdirectories Directory containing main.js, utils.js javascript files. Directory with fplayer.css cascade style sheet Directory containing all the bitmap images used by App
4. App Creation
This section will briefly show the initial configuration of the App. It assumes that basic App creation is already understood by the reader. For more detail on this part, please see the Guide tutorial.
/* If something went wrong just return to the Widget Manager */ if (!Main.init()) Utils.widgetAPI.sendReturnEvent(); Main.displayVolValue();
//Setting the buttons apparance $('playBtn').style.opacity = '0.8'; $('stopBtn').style.opacity = '0.5'; $('pauseBtn').style.opacity = '0.5'; }
Main.keyDown = function() { //TODO The content of this function will be provided in another section of this document. }
} return success; }
/** * displays current audio volume value */ Main.displayVolValue = function() { var vol = Main.pluginAudio.GetVolume(); $('volVal').replaceContent(vol); }
As you can see there are two javascript functions that are of the highest importance here. The Main.onLoad() function is called when the DOM window.onload event appears. First of all, the Main.onLoad event handler sends information to the Samsung Smart TV that the App is about to start. Next is the Main.init() function call. In it the App sets references to the plugin objects that are responsible for managing both: the middleware and audio. If the middleware plugin object has been successfully created then the media source is being changed to the App and the original source is being stored in an auxiliary object. The original source will be needed during unloading the App simply to restore the video that was previously watched by the user. The Samsung Smart TV Flash Player implementation is not capable to control sound volume since this task is dedicated to another plugin which deals with the TV sets middleware. The Main.pluginAudio object stores the reference to this plugin and allows App to manipulate sound by calling SetVolumeWithKey(0) when increase and SetVolumeWithKey(1) when decrease the volume. This feature will be discussed later in another section of this document. Now, start the SDK emulator. If you see the message of alert() : Main.onLoad(), in the log manager, that means you have successfully created the App.
function debug(message) { text1.text = text1.text + message + " \n"; text1.scroll = text1.scroll + 1; } // End of the function
// Create a NetStream object and define an onStatus() function var my_ns:NetStream = new NetStream(my_nc);
// Wire up JS external interface - exposing functions if(ExternalInterface.available){ info("onLoad: External Interface available, exposing callbacks to enclosing JavaScript"); ExternalInterface.addCallback("VideoPause", null, _externalPause); ExternalInterface.addCallback("VideoPlay", null, _externalResume); ExternalInterface.addCallback("VideoSkip", null, _externalSkip); ExternalInterface.addCallback("VideoStop", null, _externalStop);
/* * Pause playback */ function _externalPause(params:Object) :Void{ if(flagPause == 0) { my_ns.pause(); flagPause = 1; } } /** * Resume playback */ function _externalResume(params:Object) :Void{ if(flagPause == 1) { my_ns.pause(); flagPause = 0; } } /** * Seek to the given time offset from the current playheadtime */
This code is responsible for setting the initial objects that will be required by the video playback. Aside from the flagPause or volumeValue objects that play here just a second plan role the one which is more important is the my_nc:NetConnection with its connect(Uri) function call. Here in the example code it looks like: my_nc.connect("rtmpe://192.168.10.10/vod") and as it is it declares opening the network connection with a stream that is served remotely and available over the rtmpe protocol. As the server we mean here the Flash Media Server instance. Thats all we have to do if want to use secured encrypted stream for the playback. Another option is to connect over the rtmp (without encryption) and in this case we just need to remove the e letter from the URI like for instance: my_nc.connect("rtmp://192.168.10.10/vod"). After establishing connection here is the place for creating objects responsible for the acctual playback:
var flagPause = 0; var my_nc = new NetConnection(); var url = "rtmpe://192.168.10.10/vod"; // put the FMS address in here.
From now the video is started and visible for the user. That could be end of this story however what is a must for such kind of applications is a user interaction. We have to add key down event handlers to introduce such functionalities like: stop, pause, fast forward, rewind and finally play (resume) of the video. The entire event comes from the JavaScript application that in fact hosts the Flash Player. We need to expose the interface for the JavaScript that will establish communication between Flash Player and the JavaScript.
if (flash.external.ExternalInterface.available) { info("onLoad: External Interface available, exposing callbacks to enclosing JavaScript"); flash.external.ExternalInterface.addCallback("pause", null, _externalPause); flash.external.ExternalInterface.addCallback("play", null, _externalResume); flash.external.ExternalInterface.addCallback("skip", null, _externalSkip); flash.external.ExternalInterface.addCallback("stop", null, _externalStop); } else { warn("onLoad: External Interface is not available - no methods exposed"); } // end else if
Here you can find event handlers used by progress bar and indicator on the screen:
my_ns.onStatus = function (infoObject) { if (this.time == 0) { bar._width = 0; } // end if if (this.time > 0 && this.time >= movieduration 0.5)
function _externalPause(params) { if (flagPause == 0) { clearInterval(fps_interval); my_ns.pause(); flagPause = 1; } // end if } // End of the function function _externalResume(params) { fps_interval = setInterval(_displayFPS, 1000, my_ns); if (flagPause != 1) { my_ns.play(videoname); } else { my_ns.pause(); flagPause = 0; } // end else if
At the very end of the code writing (modification) we cant forgot to update the related swf file (here RTMP_Playback.swf) by selecting Publish option available in the FL Adobe Flash CS 3 (4) File menu. Thats enough to start using the interface from the JavaScript level of the App. This will be discussed in the next section.
The code above needs some comment to be clearly understood. First of all the Main.keyDown() function retrieves the pressed key value from the global event object that is provided by the MAPLE browser. All the event.keyCode values are being
Main.pause = function() { try { Utils.debug("pausing...: "); Main.player.pause(); $('playBtn').style.opacity = '0.5'; $('pauseBtn').style.opacity = '0.8'; $('stopBtn').style.opacity = '0.5'; } catch (e) { Utils.debug("Error in Main.pause() function: " + e); } }
} catch (e) { Utils.debug("Error in Main.stop() function: " + e); } } Main.skip = function(time) { try { Utils.debug("skip...: " + time + " sec."); Main.player.skip(time);
And thats all about the basic playback. We are ready to start the App and see the video. Its possible to stop the playback, skip some scenes by pressing FFW or rewind it with REW, PAUSE and then resume by pressing the PLAY button on the remote controller. Youve probably noticed the $('playBtn') which is an abbreviation of document.getElementById(playBtn). The $ function definition as well as another auxiliary function have been defined in a separate JS file named utils.js. The very last thing is adding the volume control to our App. Since the hardware specific of the TV set it had been decided to not use the Flash Player as the sound volume controller. Thats why there exists another specialized web browsers plugin, which is responsible for managing audio adjustment tasks. As it was mentioned in the stage one section of this tutorial, we have to use standard interface functions of the audio plugin like here:
Main.volUp = function()
From now all the sources are complete. We can start the App on the TV set. Of course first we have to deploy it there but this topic has been explained in details by the User App for Samsung Apps Into a TV Set tutorial published on www.samsungdforum.com web site and it is beyond the scope of this document.
5. Concluding remarks
This tutorial has explored the main functions of the Flash Player plugin used to play video stream over RTMP/RTMPe. It has also shown how to control volume using the audio plugin. Other API functions are available from the video and audio plugins, and it is recommended that you read the full API description for each plugin, which you can find in the Guide.