question

glmdev avatar image
glmdev asked

Template for On Demand Video app

Hello, Sujoy@Amazon answered my previous question. Very helpful: https://forums.developer.amazon.com/forums/message.jspa?messageID=11816 Now, I would like to know, 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. Message was edited by: glmdev
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
Hi, You can edit your video view's layout file with below xml And then from your main activity (from and event like a button pressed) you can launch the below activity what will set above layout in the view. 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"; @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(); } } To play a media from remote url you should change above code like, String mUri = " http://commonsware.com/misc/test2.3gp" mVideoView.setVideoURI(mUri); Build your using eclipse and deploy the apk in Fire TV, it should work. Please refer below links for connecting and installing the apk on Fire TV box. https://developer.amazon.com/public/solutions/devices/fire-tv/docs/connecting-adb https://developer.amazon.com/public/solutions/devices/fire-tv/docs/installing-and-running-your-app
10 |5000

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

T. Holyoak avatar image
T. Holyoak answered
Why is the video being copied before it's played? Can't it be streamed directly from the web server?
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
Yes, of course it can be streamed from a web server or media server.
10 |5000

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