Build custom media players

Build media players for the live and vod services

Adobe has developed the Open Source Media Framework (OSMF) to make it easier to build media players. OSMF is an open software framework for building robust, feature rich video players and applications based on the Flash Platform. For information about building a media player with the OSMF library, see Building streaming video players in Flash with the Adobe Open Source Media Framework.

You can also use ActionScript to build a media player from scratch. For more information, see the following:

Connect to a streaming service

Like all Adobe Media Server applications, streaming services expect a NetConnection.connect() URI in the following format:

 rtmp://ams-ip-or-dna/serviceName/[formatType:][instanceName/]fileOrStreamName

hostName

The Adobe Media Server domain name.

serviceName

Either live or vod.

instanceName

If the client is connecting to the default instance, you can either omit the instance name or use _definst_. If the client is connecting to an instance you have created, such as room1, use that name.

formatType

For mp3 files, mp3:. For MP4/F4V files, mp4:. Not required for FLV files.

fileOrStreamName

Either a filename (for example, my_video.mp4) or a path (for example, subdir/subdir2/my_video.mp4), for example, rtmp://www.examplemediaserver.com/vod/mp4:ClassicFilms/AnOldMovie.mp4. For MPEG-4-based files, if the file on the server uses a filename extension (.mp4, .f4v, and so on), specify it. If the stream is live and the publisher specified a filename extension, specify it. For instance, rtmp://www.examplemediaserver.com/live/livestream.

Unsupported ActionScript APIs

Clients for the vod and live services can use any ActionScript APIs except remote shared objects (SharedObject.getRemote()).

You cannot edit the server-side code for streaming services. However, the services do have a custom API that lets you access information from the server. Call the NetConnection.call() method from client-side code and pass it the name of the API you want to call.

Allow connections from specific domains

By default, clients can connect to the live and vod services from any domain. You can limit the domains from which clients can connect.

  1. Navigate to the rootinstall/applications/live or rootinstall/applications/vod folder and do one of the following:

    • To add a domain for SWF clients, edit the allowedSWFdomains.txt file.

    • To add a domain for HTML clients, edit the allowedHTMLdomains.txt file.

    The TXT files contain detailed information about adding domains.

Access raw audio and video data

Note:

Adobe Media Server Standard supports this feature through the Access plug-in only.

Beginning with Flash Media Server 3 and Flash Player 9.0.115, you can access raw audio and video data in streams. Use this data to create snapshots in your applications. To access the data, call the ActionScript 3.0 BitmapData.draw() and SoundMixer.computeSpectrum() methods. For more information, see ActionScript 3.0 Reference for Flash Platform.

By default, Adobe Media Server prevents you from accessing streams. To allow stream access, do the following:

  1. Move the main.far file from rootinstall/applications/live or rootinstall/applications/vod to rootinstall/samples/applications/live or rootinstall/samples/applications/vod.

    You cannot edit FAR files, so you must replace main.far with main.asc.

  2. Copy the main.asc file from rootinstall/samples/applications/live or rootinstall/samples/applications/vod to rootinstall/applications/live or rootinstall/applications/vod.

  3. Open the main.asc file in a text editor.

  4. Uncomment the following code to allow all clients to access all streams:

    //p_client.audioSampleAccess = "/"; 
    //p_client.videoSampleAccess = "/";
  5. Save the main.asc file.

Note:

The application instance requires restarting in order for the changes in the main.asc to take affect.

Streaming services API

getStreamLength()

getStreamLength(streamObj)

Returns the length of a stream, in seconds. Call this method from a client-side script and specify a response object to receive the returned value.

Availability

Flash Media Server 3, vod streaming service

Parameters

streamObj

A Stream object.

Returns

A number.

Example

The following client-side code gets the length of the sample_video stream and returns the value to returnObj:

 nc.call("getStreamLength", returnObj, "sample_video");

getPageUrl()

getPageUrl()

Returns the URL of the web page in which the client SWF file is embedded. If the SWF file isn’t embedded in a web page, the value is the location of the SWF file. The following code shows the two examples:

 // trace.swf file is embedded in trace.html. 
getPageUrl returns: http://www.example.com/trace.html 
  
 // trace.swf is not embedded in an HTML file. 
getPageUrl returns: http://www.example.com/trace.swf

The value must be an HTTP address. For security reasons, local file address (for example, file:///C:/Adobe Media Server applications/example.html) are not displayed.

Availability

Flash Media Server 3, vod streaming service, live streaming service

Example

The following example calls the getPageUrl() method on the server: nc.call("getPageUrl", returnObj);

 nc.call("getPageUrl", returnObj);

getReferrer()

getReferrer()

Returns the URL of the SWF file or the server where the connection originated.

Availability

Flash Media Server 3, vod streaming service, live streaming service

Example

The following code calls the getReferrer() method on the server:

myNetConnection.call("getReferrer", returnObj);

Build an HTTP Dynamic Streaming media player

Use Open Source Media Framework (OSMF)

You don’t need to build an HTTP Dynamic Streaming media player—the bundled players, see Pre-built media players, support HDS by default.

If you do decide to build a custom player, Adobe strongly recommends using OSMF. OSMF is a robust framework designed to deliver high-quality video. Use the pre-built Strobe Media Player as a reference implementation. The OSMF Sample Player uses the ActionScript 3.0 NetStream.appendBytes() API to deliver bytes to Flash Player and AIR.

Understanding the application flow for live HTTP Dynamic Streaming

To play a stream, a media player requests a .f4m file. The player contains logic that requests additional files when a user seeks, pauses, and plays media. The Adobe Media Server Live Packager (livepkgr application) creates these files when the server ingests a live stream or when a client requests an on-demand media file.

Note:

The HTTP Origin Module generates the .f4m file when it is requested. The file is not physically present on the disk. However, you can request the file even when a live stream has stopped publishing.

Streaming media using Adobe HDS requires Adobe Media Manifest files (.f4m).

The manifest file contains information about a media asset or information about each stream in a multiple stream event. This information can include the location of the media, DRM additional header data, media bootstrap information, adaptive streaming bitrates, and so on.

The Apache HTTP modules create the F4M and M3U8 files as the streams are packaged and written to disk. To create these files, the HTTP modules use metadata from the Event.xml file (if it exists) and data from the .f4f, .f4x, .meta, .bootstrap, .stream, and .drmmeta files.

Note:

Do not move the files from their original locations.

To generate the file, the HTTP modules follow these steps:

  1. Combine the request URL and the HttpStreamingLiveEventPath directive to locate the live event.

  2. Retrieve metadata about the event from the Event.xml file and the multi-level manifest file.

  3. Scan the event directory for stream record files (.stream).

  4. Retrieve the path to the corresponding content from each .stream file. Each .stream file becomes a <media> element in the manifest file.

  5. Retrieve metadata from the .meta file.

  6. Create links to the bootstrap information and DRM additional header data (if the content is protected).

  7. Return the generated manifest document (.f4m or .m3u8).

For more information, see the F4M File Format Specification at adobe.com.

For more information, sabout the M3U8 file, see the the HTTP Live Streaming Internet-Draft.

In the rootinstall\applications\livepkgr\streams\_definst_ folder, the Live Packager creates a folder with the name of each stream: livestream1, livestream2, and livestream3. The Live Packager creates the following files in each folder:

  • livestream#.bootstrap

  • livestream#.control

  • livestream#.meta

  • livestream#Seg#.f4f

  • livestream#Seg#.f4x

These are the files that an HTTP Dynamic Streaming media player requests to handle pausing, fast forwarding, rewinding, and so on. The following table describes each file type:

File

Description

livestream#Seg#.f4f

A segment. The Live Packager outputs one or more F4F files. Each file contains a segment of the source file. Each segment contains the fragmented (and optionally protected) content.

livestream#Seg#.f4x

An index file listing the fragment offsets in each .f4f file. The Live Packager outputs one or more F4X files. The HTTP Origin Module uses this file to deliver fragments.

livestream#.meta

Contains the stream metadata (bitrate, screen size, and so on).

livestream#.bootstrap

Contains the bootstrap information for the stream.

livestream#.control

Contains internal metadata that the Live Packager uses to manage stream state.

livestream#.drmmeta

Contains additional header information when a stream is encrypted for use with Adobe Access.

The following are the URL request formats for these files when Apache is configured for HTTP Dynamic Streaming:

Request type

URL Form

Fragment

http://<host>/<location-tag-alias>/streams/<app-name>/streams/<app-instance>/<stream name>Seg<segment #>-Frag<fragment #>

Note:You cannot request an F4F file directly. Request a Fragment.

Bootstrap (.bootstrap)

http://<host>/<location-tag-alias>/streams/<app-name>/streams/<app-instance>/<stream name>.bootstrap

For more information about configuring Apache for HTTP Dynamic Streaming, see Apache configurations for HTTP Dynamic Streaming.

Stream record files

A stream record file (.stream) is an XML document that contains the physical location of the stream. The server creates the stream record file when an incoming stream is associated with a live event. The server creates the file with an encoded name in the following location:

applications/appname/events/appinstancename/eventname/MTg1ODAyNjgwNg=.stream

The HTTP Origin Module reads the stream record file to locate the content for the stream. The following is the format of the .stream file:

<?xml version="1.0" encoding="UTF-8"?> 
<stream xmlns="http://www.adobe.com/liveevent/1.0"> 
    <type> 
        f4f 
    </type> 
    <name> 
        livestream 
    </name> 
    <path> 
        C:\Program Files\Adobe\Adobe Media Server 5\applications\myapp\streams\_definst_\livestream            
        </path> 
</stream>

Sample .f4m manifest file

The player uses the manifest file to request a content fragment. In the following example, there are two streams associated with the live event, “livestream” and “livestream1”. The <media> elements provide the absolute URL path to the content location with the prefix “/live/streams”.

If .bootstrap and .drmmeta are found in the same location as the .f4f file, <bootstrap> and <drmAdditionalHeader> elements are included in the manifest file. The drmContentId attribute under drmAdditionalHeader element shows the path of the file without the file name. The .drmmeta file can be shared across multiple streams, therefore there is only one <drmAdditionalHeader> element in the sample manifest file. Both myStream and myStream1 refer to the same .drmmeta file through the drmAdditionalHeaderId attribute.

The metadata element contains the metadata for one piece of media in Base64 encoding. The metadata is the same information dispatched in the ActionScript NetStream.onMetaData() event.

<?xml version="1.0" encoding="UTF-8" ?> 
<manifest xmlns="http://ns.adobe.com/f4m/1.0"> 
    <id>live_mbr_event</id> 
    <streamType>live</streamType> 
    <duration>0</duration> 
    <bootstrapInfo 
        profile="named" 
        url="/live/streams/myStream.bootstrap" 
        id="bootstrap2267" /> 
    <drmAdditionalHeader 
        url="/live/streams/myStream.drmmeta" 
        drmContentId="live_mbr_event" 
        id="drmMetadata9996" /> 
    <media> 
        url="/live/streams/myStream" 
        bitrate="408" 
        bootstrapInfoId="bootstrap2267" 
        drmAdditionalHeaderId="drmMetadata9996"> 
        <metadata>    AgAKb25NZXRhRGF0YQgAAAAAAAhkdXJhdGlvbgBARo9cKPXCjwAFd2lkdGgAQJQAAAAAAAAABmhlaWdodABAho 
AAAAAAAAAMdmlkZW9jb2RlY2lkAgAEYXZjMQAMYXVkaW9jb2RlY2lkAgAEbXA0YQAKYXZjcHJvZmlsZQBAWQAA 
AAAAAAAIYXZjbGV2ZWwAQEAAAAAAAAAABmFhY2FvdAAAAAAAAAAAAAAOdmlkZW9mcmFtZXJhdGUAQD34U+JVay 
gAD2F1ZGlvc2FtcGxlcmF0ZQBA53AAAAAAAAANYXVkaW9jaGFubmVscwBAAAAAAAAAAAAJdHJhY2tpbmZvCgAA 
AAIDAAZsZW5ndGgAQTSinwAAAAAACXRpbWVzY2FsZQBA3UwAAAAAAAAIbGFuZ3VhZ2UCAANlbmcAAAkDAAZsZW 
5ndGgAQUCGAAAAAAAACXRpbWVzY2FsZQBA53AAAAAAAAAIbGFuZ3VhZ2UCAANlbmcAAAkAAAk= 
        </metadata> 
    </media> 
    <bootstrapInfo 
        profile="named" 
        url="/live/streams/myStream1.bootstrap" 
        id="bootstrap7975" /> 
    <media> 
        url="/live/streams/myStream1" 
        bitrate="1108" 
        bootstrapInfoId="bootstrap7975" 
        drmAdditionalHeaderId="drmMetadata9996"> 
        <metadata>    AgAKb25NZXRhRGF0YQgAAAAAAAhkdXJhdGlvbgBARo9cKPXCjwAFd2lkdGgAQJQAAAAAAAAABmhlaWdodABAho 
AAAAAAAAAMdmlkZW9jb2RlY2lkAgAEYXZjMQAMYXVkaW9jb2RlY2lkAgAEbXA0YQAKYXZjcHJvZmlsZQBAWQAA 
AAAAAAAIYXZjbGV2ZWwAQEAAAAAAAAAABmFhY2FvdAAAAAAAAAAAAAAOdmlkZW9mcmFtZXJhdGUAQD34U+JVay 
gAD2F1ZGlvc2FtcGxlcmF0ZQBA53AAAAAAAAANYXVkaW9jaGFubmVscwBAAAAAAAAAAAAJdHJhY2tpbmZvCgAA 
AAIDAAZsZW5ndGgAQTSinwAAAAAACXRpbWVzY2FsZQBA3UwAAAAAAAAIbGFuZ3VhZ2UCAANlbmcAAAkDAAZsZW 
5ndGgAQUCGAAAAAAAACXRpbWVzY2FsZQBA53AAAAAAAAAIbGFuZ3VhZ2UCAANlbmcAAAkAAAk= 
        </metadata> 
    </media> 
</manifest>