Play video from json urls in Amazon Fire TV

Posted By : Rohit Kaushik | 12-Nov-2014

In the previous blog , I explained you how to load a image from JSON. That JSON have a jsonarray i.e. “video”. Video jsonarray have many fields  likes title , description , url , thumbnail.


{ 
    "video": [{ 
	        "title": "logo check", 
			"Description": "This is the description of Ist video", 
			"url": "http://my.development.streaming01.mediacatapult.com:1935/vod/_definst_/6336/Media/64454_55662/Transcoded/smil:64454_55662_destinationId_180.smil/playlist.m3u8", 
			"thumbnail": { 
			      "thumbnailHD": "http://oodles.development.mediacatapult.com/storage/6336/Media/64454_55662/Thumbnails/64454_55662_1251_1HD.png", 
				  } 
		},{ 
		    "title": "logo check", 
			"Description": "This is the description of Ist video", 
			"url": "http://my.development.streaming01.mediacatapult.com:1935/vod/_definst_/mp3:6336/Media/16336_71147/Transcoded/16336_7114732320_53116.mp3/playlist.m3u8", 
			"thumbnail": { 
			      "thumbnailHD": "http://oodles.development.mediacatapult.com/storage/6336/Media/52300_42202/Thumbnails/52300_42202_567_1HD.png", 
				  } 
		}] 
} 

Now I will explain you how to play a video in Amazon Fire TV app.In the previous blog we parse this json.Now I call a VideoActivity class for playing a video.
We have to create a different activity because we want to play a video on another window. Whenever we want to perform any task on a seperate window then we have to create an another Activity class. For starting another activity we have to use "Intent".
An Intent is an object that provides runtime binding between separate components (such as two activities).
In MainActivity.java we used Intent and pass "VideoActivity.class" as a argument.


Intent in = new Intent(getApplicationContext(),VideoActivity.class); 
in.putExtra(TAG_URL, Video); 
startActivity(in); 

 The putExtra() method takes the key name in the first parameter and the value in the second parameter.


public class VideoActivity extends Activity { 
	 
	private static final String TAG_URL = "url"; 
	public MediaController mediaController; 
	public ProgressDialog pDialog; 
	public VideoView videoView; 
	public String videourl; 
	public Uri video; 
	@Override 
	protected void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState); 
		setContentView(R.layout.activity_video); 
		try{ 
		    Intent in = getIntent(); 
		    videourl = in.getStringExtra(TAG_URL); 
			videoView = (VideoView) findViewById(R.id.video_view); 
			mediaController=new MediaController(VideoActivity.this); 
		    mediaController.setAnchorView(videoView); 
			video=Uri.parse(videourl); 
			videoView.setMediaController(mediaController); 
		    videoView.setVideoURI(video); 
		    videoView.requestFocus(); 
			videoView.start(); 
			} 
		catch(Exception e){ 
			// TODO: handle exception 
			Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show(); 
		} 
	} 
}	 

This simplest way to display the video in our fire tv application is to use VideoView class.
This is a visual component which, when added to the layout of an activity, provides a surface onto which a video played.
If a video is simply played using the VideoView class, the user will not be given any control over the playback,which will run until the end of the video is reached. This issue can be addressed by attaching an instance of the MediaController class to the VideoView instance. The MediaController will then provide a set of controls allowing the user to manage the playback (such as pausing and seeking backwards/forwards in the video timeline).

I hope this will be helpful for you.

Thankyou

Rohit Kaushik     

Related Tags

About Author

Author Image
Rohit Kaushik

Rohit is a bright IPTV Developer and have worked on various developments.

Request for Proposal

Name is required

Comment is required

Sending message..