SampleVideoSupportFragment.java revision 95ac470f2bbea06114a64906d95c0da7d9412db0
1// CHECKSTYLE:OFF Generated code 2/* This file is auto-generated from OnboardingDemoFragment.java. DO NOT MODIFY. */ 3 4/* 5 * Copyright (C) 2016 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 8 * in compliance with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed under the License 13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 14 * or implied. See the License for the specific language governing permissions and limitations under 15 * the License. 16 */ 17package com.example.android.leanback; 18 19import android.net.Uri; 20import android.os.Bundle; 21import android.support.v17.leanback.app.VideoSupportFragmentGlueHost; 22import android.support.v17.leanback.media.MediaPlayerGlue; 23import android.support.v17.leanback.media.PlaybackGlue; 24 25/** 26 * Fragment demonstrating the use of {@link android.support.v17.leanback.app.VideoSupportFragment} to 27 * render video with playback controls. 28 */ 29public class SampleVideoSupportFragment extends android.support.v17.leanback.app.VideoSupportFragment { 30 private MediaPlayerGlue mMediaPlayerGlue; 31 32 @Override 33 public void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 } 36 37 @Override 38 public void onStart() { 39 super.onStart(); 40 } 41 42 VideoSupportFragmentGlueHost host = new VideoSupportFragmentGlueHost(SampleVideoSupportFragment.this); 43 44 @Override 45 public void onResume() { 46 super.onResume(); 47 getView().postDelayed(new Runnable() { 48 @Override 49 public void run() { 50 mMediaPlayerGlue = new MediaPlayerGlue(getActivity()); 51 mMediaPlayerGlue.setMode(MediaPlayerGlue.REPEAT_ALL); 52 mMediaPlayerGlue.setPlayerCallback(new PlaybackGlue.PlayerCallback() { 53 @Override 54 public void onReadyForPlayback() { 55 mMediaPlayerGlue.play(); 56 } 57 }); 58 mMediaPlayerGlue.setArtist("Leanback"); 59 mMediaPlayerGlue.setTitle("Leanback team at work"); 60 String uriPath = "android.resource://com.example.android.leanback/raw/browse"; 61 mMediaPlayerGlue.setMediaSource(Uri.parse(uriPath)); 62 mMediaPlayerGlue.setHost(host); 63 } 64 }, 500); 65 66 67 getView().postDelayed(new Runnable() { 68 @Override 69 public void run() { 70 mMediaPlayerGlue = new MediaPlayerGlue(getActivity()); 71 mMediaPlayerGlue.setMode(MediaPlayerGlue.REPEAT_ALL); 72 mMediaPlayerGlue.setPlayerCallback(new PlaybackGlue.PlayerCallback() { 73 @Override 74 public void onReadyForPlayback() { 75 mMediaPlayerGlue.play(); 76 } 77 }); 78 mMediaPlayerGlue.setArtist("A Googler"); 79 mMediaPlayerGlue.setTitle("Swimming with the fishes"); 80 81 mMediaPlayerGlue.setVideoUrl("http://techslides.com/demos/sample-videos/small.mp4"); 82 mMediaPlayerGlue.setHost(host); 83 } 84 }, 3000); 85 } 86} 87