1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view.cts; 18 19 import android.app.Activity; 20 import android.cts.util.MediaUtils; 21 import android.net.Uri; 22 import android.os.Bundle; 23 import android.util.Log; 24 import android.widget.VideoView; 25 26 import java.util.concurrent.CountDownLatch; 27 28 public class PixelCopyVideoSourceActivity extends Activity { 29 private static final String TAG = "PixelCopyVideoSourceActivity"; 30 private VideoView mVideoView; 31 private CountDownLatch mVideoPlayingFence = new CountDownLatch(1); 32 private boolean mCanPlayVideo; 33 34 @Override onCreate(Bundle savedInstanceState)35 protected void onCreate(Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 mVideoView = new VideoView(this); 38 mVideoView.setOnPreparedListener(mp -> { 39 mp.setLooping(true); 40 mVideoView.start(); 41 mVideoPlayingFence.countDown(); 42 }); 43 mVideoView.setOnErrorListener((mp, what, extra) -> { 44 Log.e(TAG, "MediaPlayer encountered error " + what + ", " + extra); 45 mCanPlayVideo = false; 46 mVideoPlayingFence.countDown(); 47 return true; 48 }); 49 mCanPlayVideo = MediaUtils.hasCodecsForResource(this, R.raw.colorgrid_video); 50 if (mCanPlayVideo) { 51 Uri uri = Uri.parse("android.resource://android.view.cts/" + R.raw.colorgrid_video); 52 mVideoView.setVideoURI(uri); 53 } 54 setContentView(mVideoView); 55 } 56 canPlayVideo()57 public boolean canPlayVideo() { 58 return mCanPlayVideo; 59 } 60 waitForPlaying()61 public void waitForPlaying() throws InterruptedException { 62 mVideoPlayingFence.await(); 63 } 64 getVideoView()65 public VideoView getVideoView() { 66 return mVideoView; 67 } 68 } 69