question

glmdev avatar image
glmdev asked

On-demand video app for FireTV

Hello, I am wondering if someone could offer a few pointers on developing an on-demand video app for Fire TV. For example, is it possible to use our videos from YouTube or Vimeo like we would in an Android phone/tablet app? If not, what kind of code would I use to include .mp4 videos that actually play on the FireTV device? Any help is greatly appreciated. Thanks.
fire tv
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Sample code to play a mp4 media public class VideoPlayer extends Activity implements MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener { private VideoView mVideoView; private Uri mUri; private int mPositionWhenPaused = -1; private MediaController mMediaController; private String mediaFileName = "test.mp4"; // private String mediaFileName = "channelcheck-small.mkv"; // private String mediaFileName = "cc.mp4"; // private String mediaFileName = "sample.avi"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Set the screen to landscape. this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); mVideoView = (VideoView) findViewById(R.id.video_view); //Video file mMediaController = new MediaController(this); mVideoView.setMediaController(mMediaController); copyMediaToDataDirectory(); } private void copyMediaToDataDirectory() { File dest = this.getDir("Other", MODE_PRIVATE); try { InputStream srcFileStream = this.getAssets().open(mediaFileName); copyFile(srcFileStream, dest.getAbsolutePath(), mediaFileName); // Copying the file to data directory mVideoView.setVideoURI(mUri); mVideoView.start(); } catch (IOException e) { System.out.println("Exception copying"); e.printStackTrace(); } } private void copyFile(InputStream srcFileStream, String targetLocation, String destFileName) throws IOException { String destFilePath = targetLocation + "/" + destFileName; System.out.println("destFilePath = " + destFilePath); OutputStream out = new FileOutputStream(destFilePath); byte[] buf = new byte[1024]; int len; while ((len = srcFileStream.read(buf)) > 0) { out.write(buf, 0, len); } srcFileStream.close(); out.close(); mUri = Uri.parse(destFilePath); } public void onPause() { // Stop video when the activity is pause. mPositionWhenPaused = mVideoView.getCurrentPosition(); mVideoView.stopPlayback(); super.onPause(); } public void onResume() { // Resume video player if (mPositionWhenPaused >= 0) { mVideoView.seekTo(mPositionWhenPaused); mPositionWhenPaused = -1; } super.onResume(); } public boolean onError(MediaPlayer player, int arg1, int arg2) { System.out.println("VideoPlayer.onError"); System.out.println("arg1 = " + arg1); System.out.println("arg2 = " + arg2); return false; } public void onCompletion(MediaPlayer mp) { this.finish(); } }
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

glmdev avatar image
glmdev answered
OK. Thank you, that helps a lot. Will this still work if I use an external URL starting with http:// ?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

glmdev avatar image
glmdev answered
Where do I place this code in the context of a FireTV app being developed in Eclipse? The Amazon FireTV SDK templates do not show any examples for a simple on demand video app. I would like to start with one video and then add more. How can I do this? Any help is appreciated.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
VideoView works with http url mVideoView.setVideoURI(uri); There is no Video Player specific API exposed for Fire TV, that's why there is no specific sample provided with SDK add ons. The standard Android APIs related to video would work on Fire TV. Please reach us if you face issues or difficulties implementing videos in your Fire TV us. Thanks.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.