Using RTMP Streaming

This page has moved to a new location.  Please visit the updated location here.

Thanks for your patience while we update our documentation.

You will be automatically redirected in 10 seconds.

Embedding an RTMP stream into JW Player is simply a matter of providing the full stream URL. Here is a very basic example, playing a single MP4 video:

var playerInstance = jwplayer("myElement");
playerInstance.setup({
	file: "rtmp://example.com/application/mp4:myVideo.mp4",
	image: "/assets/myVideo.jpg",
	height: 360,
	width: 640
});

Above example only works on desktops, since Flash is not available on mobile/HTML5. Below is another example, using an MP4 loaded over both RTMP and HTTP. The RTMP stream will be played on desktops, the HTTP download will be played on devices:

 
var playerInstance = jwplayer("myElement");
playerInstance.setup({
	playlist: [{
	image: "/assets/myVideo.jpg",
		sources: [{ 
			file: "rtmp://example.com/application/mp4:myVideo.mp4"
		},{
			file: "/assets/myVideo.mp4"
		}]
	}],
height: 360,
primary: "flash",
width: 640
});

Since the primary rendering mode is set to Flash, the RTMP stream is picked over the MP4. If this option were not set, the JW Player would play the HTTP download, since many browsers (e.g. Chrome, Internet Explorer) support that in HTML5 (the default mode in JW).

See Working with Playlists for more info on loading multiple sources.

Application and Stream

Technically, an RTMP stream consists of two pieces:

  • The application path (e.g. rtmp://example.com/vod/).
  • The stream identifier (e.g. mp4:myFolder/video.mp4).

In JW Player, these two pieces are rolled up into a single URL. JW Player determines the split between application and stream based upon the location of the mp4, flv or mp3 prefix.

  1. An mp4: prefix is required for MP4/M4V/MOV/F4V videos:
    rtmp://example.com/vod/mp4:myFolder/myVideo.mp4
  2. An flv: prefix is required for FLV videos or live streams (with FLV container):
    rtmp://example.com/vod/flv:myFolder/myVideo.flv
    rtmp://example.com/live/flv:myFolder/myLiveStream
    
  3. An mp3: prefix is required for MP3 audio:
    rtmp://example.com/vod/mp3:myFolder/mySong.mp3
    
  4. An mp4: prefix is also required for M4A/F4A/AAC audio files:
    rtmp://example.com/vod/mp4:myFolder/mySong.m4a
    

If no prefix is found, the player splits application/stream after the last / in the filename. The prefix is then automatically added (mp4:, mp3:). Note the flv prefix is not used internally by the Wowza/Adobe server, so JW Player strips that one out before requesting the stream.

Configuration Options

RTMP supports a few configuration options to tweak playback of the streams. They are set in a dedicated rtmp options block.

Buffer Length

By default, JW Player tries to maintain a buffer length of 3 seconds for RTMP video. This means that 3 seconds of video is fetched from the server and ready to play at all times. This can be changed to another value using the RTMP bufferlength option:

var playerInstance = jwplayer("myElement"); 
playerInstance.setup({
	file: "rtmp://example.com/vod/mp4:myVideo.mp4",
    image: "/assets/myVideo.jpg",
    height: 360,
	width: 640,
    rtmp: {
        bufferlength: 0.1
    }
});

Sane values range from 0.1 (for low latency live streams) to 10 (to prevent frequent re-buffering).

FC Subscribe

When streaming RTMP live streams using the Akamai, Edgecast or Limelight CDN, players cannot simply connect to the live stream. Instead, they have to subscribe to it, by sending a so-called FC Subscribe call to the server. JW Player includes support for this, using the RTMP subscribe option:

var playerInstance = jwplayer("myElement");
playerInstance.setup({
    file: "rtmp://example.com/xxxx/myStream",
    height: 360,
    width: 640,
    image: "/assets/myLivestream.jpg",
    rtmp: {
        subscribe: true
    }
});

Note this functionality only works for single RTMP streams. For multi-bitrate live streaming, the HLS protocol should be used.

Secure Token

The Wowza Media Server includes a feature called Secure Token that is used to protect your streams from downloading. It works by having the player send a token to the server, which is verified before the stream is started. JW Player supports this mechanism, using the RTMP securetoken option:

var playerInstance = jwplayer("myElement");
playerInstance.setup({
	file: "rtmp://example.com/vod/mp4:myVideo.mp4",
	height: 360,
	width: 640
	image: "/assets/myVideo.jpg",
	rtmp: {
		securetoken: "Kosif093n203a"
	}
});

Note we do not support the option to compile in the securetoken. SWF provides little incremental security over JS (they're both client-side), especially when the JS code is slightly obfuscated.

Did you find this article helpful?

Please log in to rate this article.