| /* |
| * Copyright (C) 2016 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License |
| */ |
| |
| package com.google.android.leanbackjank.ui; |
| |
| import android.app.Activity; |
| import android.content.Intent; |
| import android.media.MediaPlayer; |
| import android.media.MediaPlayer.OnPreparedListener; |
| import android.net.Uri; |
| import android.os.Build; |
| import android.os.Bundle; |
| import android.view.Window; |
| import android.view.WindowManager; |
| import android.widget.VideoView; |
| |
| public class VideoActivity extends Activity { |
| |
| private VideoView mVideoView; |
| |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| |
| requestWindowFeature(Window.FEATURE_NO_TITLE); |
| getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, |
| WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| |
| mVideoView = new VideoView(this); |
| mVideoView.setOnPreparedListener(new OnPreparedListener() { |
| @Override |
| public void onPrepared(MediaPlayer mp) { |
| mp.setLooping(true); |
| } |
| }); |
| setContentView(mVideoView); |
| |
| if (checkIntent(getIntent())) { |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| enterPictureInPictureMode(); |
| } |
| } |
| } |
| |
| private void playVideo(Uri uri) { |
| mVideoView.setVideoURI(uri); |
| mVideoView.start(); |
| } |
| |
| private boolean checkIntent(Intent intent) { |
| if (Intent.ACTION_VIEW.equals(intent.getAction())) { |
| Uri uri = intent.getData(); |
| playVideo(uri); |
| return true; |
| } else { |
| finish(); |
| return false; |
| } |
| } |
| |
| @Override |
| protected void onNewIntent(Intent intent) { |
| super.onNewIntent(intent); |
| checkIntent(intent); |
| } |
| |
| @Override |
| protected void onStop() { |
| if (mVideoView != null) { |
| mVideoView.stopPlayback(); |
| } |
| super.onStop(); |
| finish(); |
| } |
| } |