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.net.Uri; 21 import android.os.Bundle; 22 import android.util.Log; 23 import android.widget.VideoView; 24 25 import com.android.compatibility.common.util.MediaUtils; 26 27 import java.util.concurrent.CountDownLatch; 28 29 public class PixelCopyVideoSourceActivity extends Activity { 30 private static final String TAG = "PixelCopyVideoSourceActivity"; 31 private VideoView mVideoView; 32 private CountDownLatch mVideoPlayingFence = new CountDownLatch(1); 33 private boolean mCanPlayVideo; 34 35 @Override onCreate(Bundle savedInstanceState)36 protected void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 mVideoView = new VideoView(this); 39 mVideoView.setOnPreparedListener(mp -> { 40 mp.setLooping(true); 41 mVideoView.start(); 42 mVideoPlayingFence.countDown(); 43 }); 44 mVideoView.setOnErrorListener((mp, what, extra) -> { 45 Log.e(TAG, "MediaPlayer encountered error " + what + ", " + extra); 46 mCanPlayVideo = false; 47 mVideoPlayingFence.countDown(); 48 return true; 49 }); 50 mCanPlayVideo = MediaUtils.hasCodecsForResource(this, R.raw.colorgrid_video); 51 if (mCanPlayVideo) { 52 Uri uri = Uri.parse("android.resource://android.view.cts/" + R.raw.colorgrid_video); 53 mVideoView.setVideoURI(uri); 54 } 55 setContentView(mVideoView); 56 } 57 canPlayVideo()58 public boolean canPlayVideo() { 59 return mCanPlayVideo; 60 } 61 waitForPlaying()62 public void waitForPlaying() throws InterruptedException { 63 mVideoPlayingFence.await(); 64 } 65 getVideoView()66 public VideoView getVideoView() { 67 return mVideoView; 68 } 69 } 70