Add VideoView to Audio/VideoPlayerActivity

It loads media2-widget library from prebuilts to use latest version of
the library. Please ensure that prebuilts/sdk repo is synced.

Test: Play an audio/video manually
Change-Id: Ib4f306c34366cb8a8d087ee9dbc5c96314f1b6e3
diff --git a/apps/Pump/build.gradle b/apps/Pump/build.gradle
index 13b8cec..459a46a 100644
--- a/apps/Pump/build.gradle
+++ b/apps/Pump/build.gradle
@@ -20,7 +20,7 @@
     compileSdkVersion 28
     buildToolsVersion '28.0.3'
     defaultConfig {
-        minSdkVersion 16
+        minSdkVersion 19 // TODO: Lower to 16 after media2-widget supports 16
         targetSdkVersion 28
         versionCode 1
         versionName '1.0'
@@ -46,6 +46,7 @@
 dependencies {
     implementation 'androidx.appcompat:appcompat:1.0.2'
     implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
+    implementation 'androidx.media2:media2-widget:1.0.0-alpha06'
     implementation 'androidx.mediarouter:mediarouter:1.0.0'
     implementation 'com.google.android.material:material:1.0.0'
 }
diff --git a/apps/Pump/java/com/android/pump/activity/AudioPlayerActivity.java b/apps/Pump/java/com/android/pump/activity/AudioPlayerActivity.java
index a3fbe59..f42c2a7 100644
--- a/apps/Pump/java/com/android/pump/activity/AudioPlayerActivity.java
+++ b/apps/Pump/java/com/android/pump/activity/AudioPlayerActivity.java
@@ -23,15 +23,23 @@
 import android.os.Bundle;
 import android.provider.MediaStore;
 
+import com.android.pump.R;
 import com.android.pump.db.Audio;
+import com.android.pump.util.Clog;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.UiThread;
 import androidx.appcompat.app.AppCompatActivity;
+import androidx.media2.UriMediaItem;
+import androidx.media2.widget.VideoView;
 
 @UiThread
 public class AudioPlayerActivity extends AppCompatActivity {
+    private static final String TAG = Clog.tag(AudioPlayerActivity.class);
+
+    private VideoView mVideoView;
+
     public static void start(@NonNull Context context, @NonNull Audio audio) {
         // TODO Find a better URI (audio.getUri()?)
         Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
@@ -45,5 +53,21 @@
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_audio_player);
+        mVideoView = findViewById(R.id.video_view);
+
+        handleIntent();
+    }
+
+    private void handleIntent() {
+        Intent intent = getIntent();
+        Uri uri = intent.getData();
+        if (uri == null) {
+            Clog.e(TAG, "The intent has no uri. Finishing activity...");
+            finish();
+            return;
+        }
+        UriMediaItem mediaItem = new UriMediaItem.Builder(this, uri).build();
+        mVideoView.setMediaItem(mediaItem);
     }
 }
diff --git a/apps/Pump/java/com/android/pump/activity/VideoPlayerActivity.java b/apps/Pump/java/com/android/pump/activity/VideoPlayerActivity.java
index 5884dda..21e2cac 100644
--- a/apps/Pump/java/com/android/pump/activity/VideoPlayerActivity.java
+++ b/apps/Pump/java/com/android/pump/activity/VideoPlayerActivity.java
@@ -23,15 +23,23 @@
 import android.os.Bundle;
 import android.provider.MediaStore;
 
+import com.android.pump.R;
 import com.android.pump.db.Video;
+import com.android.pump.util.Clog;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.UiThread;
 import androidx.appcompat.app.AppCompatActivity;
+import androidx.media2.UriMediaItem;
+import androidx.media2.widget.VideoView;
 
 @UiThread
 public class VideoPlayerActivity extends AppCompatActivity {
+    private static final String TAG = Clog.tag(VideoPlayerActivity.class);
+
+    private VideoView mVideoView;
+
     public static void start(@NonNull Context context, @NonNull Video video) {
         // TODO Find a better URI (video.getUri()?)
         Uri uri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
@@ -45,5 +53,21 @@
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_video_player);
+        mVideoView = findViewById(R.id.video_view);
+
+        handleIntent();
+    }
+
+    private void handleIntent() {
+        Intent intent = getIntent();
+        Uri uri = intent.getData();
+        if (uri == null) {
+            Clog.e(TAG, "The intent has no uri. Finishing activity...");
+            finish();
+            return;
+        }
+        UriMediaItem mediaItem = new UriMediaItem.Builder(this, uri).build();
+        mVideoView.setMediaItem(mediaItem);
     }
 }
diff --git a/apps/Pump/res/layout/activity_audio_player.xml b/apps/Pump/res/layout/activity_audio_player.xml
new file mode 100644
index 0000000..1eac3bd
--- /dev/null
+++ b/apps/Pump/res/layout/activity_audio_player.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright 2018 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.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <androidx.media2.widget.VideoView
+        android:id="@+id/video_view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+    />
+
+</LinearLayout>
diff --git a/apps/Pump/res/layout/activity_video_player.xml b/apps/Pump/res/layout/activity_video_player.xml
new file mode 100644
index 0000000..1eac3bd
--- /dev/null
+++ b/apps/Pump/res/layout/activity_video_player.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright 2018 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.
+-->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <androidx.media2.widget.VideoView
+        android:id="@+id/video_view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+    />
+
+</LinearLayout>
diff --git a/build.gradle b/build.gradle
index a19659a..958133c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -27,8 +27,10 @@
 allprojects {
     repositories {
         jcenter()
-        maven { url 'https://maven.google.com' }
         google()
+
+        // TODO: Remove before releasing and after stable media2 is released
+        maven { url "$rootDir/../../../prebuilts/sdk/current/androidx/m2repository" }
     }
 }