In demo-misc-vp9-opus-sw removed FilePickerActivity and copied demo player permissions bug fix

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=111689012
This commit is contained in:
eguven 2016-01-08 06:10:04 -08:00 committed by Oliver Woodman
parent b9ec51dbed
commit 86c4fb3ac2
8 changed files with 69 additions and 215 deletions

View file

@ -44,14 +44,11 @@
</intent-filter>
</activity>
<activity android:name="com.google.android.exoplayer.demo.vp9opus.VideoPlayer"
<activity android:name=".PlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:theme="@style/PlayerTheme"/>
<activity android:name="com.google.android.exoplayer.demo.vp9opus.FilePickerActivity"
android:theme="@android:style/Theme.Dialog"/>
</application>
</manifest>

View file

@ -57,9 +57,9 @@ public class DashRendererBuilder implements ManifestCallback<MediaPresentationDe
private final String manifestUrl;
private final String userAgent;
private final VideoPlayer player;
private final PlayerActivity player;
public DashRendererBuilder(String manifestUrl, String userAgent, VideoPlayer player) {
public DashRendererBuilder(String manifestUrl, String userAgent, PlayerActivity player) {
this.manifestUrl = manifestUrl;
this.userAgent = userAgent;
this.player = player;

View file

@ -1,95 +0,0 @@
/*
* Copyright (C) 2014 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.exoplayer.demo.vp9opus;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* A simple file picker.
*/
public class FilePickerActivity extends ListActivity {
public static final String FILENAME_EXTRA_ID = "filename";
private List<String> listItems;
private List<File> itemPaths;
private TextView currentPathView;
private File root;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_picker_activity);
setResult(Activity.RESULT_CANCELED);
currentPathView = (TextView) findViewById(R.id.path);
root = new File(Environment.getExternalStorageDirectory().getPath());
setDirectory(root);
}
private void setDirectory(File directory) {
currentPathView.setText(getString(R.string.current_path, directory.getAbsolutePath()));
listItems = new ArrayList<>();
itemPaths = new ArrayList<>();
File[] files = directory.listFiles();
if (!directory.getAbsolutePath().equals(root.getAbsolutePath())) {
listItems.add(root.getAbsolutePath());
itemPaths.add(root);
listItems.add("../");
itemPaths.add(new File(directory.getParent()));
}
if (files != null) {
for (File file : files) {
if (!file.isHidden() && file.canRead()) {
itemPaths.add(file);
if (file.isDirectory()) {
listItems.add(file.getName() + File.separator);
} else {
listItems.add(file.getName());
}
}
}
}
setListAdapter(new ArrayAdapter<>(this, R.layout.rows, listItems));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
File file = itemPaths.get(position);
if (file.isDirectory() && file.canRead()) {
setDirectory(itemPaths.get(position));
} else {
Intent intent = new Intent();
intent.putExtra(FILENAME_EXTRA_ID, file.getAbsolutePath());
setResult(Activity.RESULT_OK, intent);
finish();
}
}
}

View file

@ -30,8 +30,11 @@ import com.google.android.exoplayer.upstream.DefaultUriDataSource;
import com.google.android.exoplayer.util.PlayerControl;
import com.google.android.exoplayer.util.Util;
import android.Manifest.permission;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@ -39,32 +42,23 @@ import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
/**
* Sample player that shows how to use ExoPlayer Extensions to playback VP9 Video and Opus Audio.
*/
public class VideoPlayer extends Activity implements OnClickListener,
LibvpxVideoTrackRenderer.EventListener, ExoPlayer.Listener {
public class PlayerActivity extends Activity implements
LibvpxVideoTrackRenderer.EventListener, ExoPlayer.Listener {
public static final String DASH_MANIFEST_URL_ID_EXTRA = "manifest_url";
public static final String USE_OPENGL_ID_EXTRA = "use_opengl";
private static final int FILE_PICKER_REQUEST = 1;
private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
private static final int BUFFER_SEGMENT_COUNT = 160;
private boolean isDash;
private String manifestUrl;
private boolean useOpenGL;
private String filename;
private ExoPlayer player;
private Handler handler;
@ -75,14 +69,14 @@ public class VideoPlayer extends Activity implements OnClickListener,
private TextView debugInfoView;
private String debugInfo;
private String playerState;
private Uri contentUri;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
manifestUrl = intent.getStringExtra(DASH_MANIFEST_URL_ID_EXTRA);
isDash = manifestUrl != null;
contentUri = intent.getData();
useOpenGL = intent.getBooleanExtra(USE_OPENGL_ID_EXTRA, true);
handler = new Handler();
@ -109,16 +103,17 @@ public class VideoPlayer extends Activity implements OnClickListener,
debugInfoView = (TextView) findViewById(R.id.debug_info);
debugInfo = "";
playerState = "";
filename = "";
updateDebugInfoTextView();
// Set the buttons' onclick listeners.
((Button) findViewById(R.id.choose_file)).setOnClickListener(this);
((Button) findViewById(R.id.play)).setOnClickListener(this);
if (!maybeRequestPermission()) {
startPlayback();
}
}
// In case of DASH, start playback right away.
if (isDash) {
findViewById(R.id.buttons).setVisibility(View.GONE);
private void startPlayback() {
if (Util.isLocalFileUri(contentUri)) {
startBasicPlayback();
} else {
startDashPlayback();
}
}
@ -129,44 +124,13 @@ public class VideoPlayer extends Activity implements OnClickListener,
stopPlayback();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.choose_file:
Intent intent = new Intent();
intent.setClass(this, FilePickerActivity.class);
startActivityForResult(intent, FILE_PICKER_REQUEST);
break;
case R.id.play:
startBasicPlayback();
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_PICKER_REQUEST:
if (resultCode == Activity.RESULT_OK) {
filename = data.getStringExtra(FilePickerActivity.FILENAME_EXTRA_ID);
updateDebugInfoTextView();
}
break;
}
}
private void startBasicPlayback() {
if (filename == null) {
Toast.makeText(this, "Choose a file!", Toast.LENGTH_SHORT).show();
return;
}
findViewById(R.id.buttons).setVisibility(View.GONE);
player = ExoPlayer.Factory.newInstance(2);
player.addListener(this);
mediaController.setMediaPlayer(new PlayerControl(player));
mediaController.setEnabled(true);
ExtractorSampleSource sampleSource = new ExtractorSampleSource(
Uri.fromFile(new File(filename)),
contentUri,
new DefaultUriDataSource(this, Util.getUserAgent(this, "ExoPlayerExtWebMDemo")),
new DefaultAllocator(BUFFER_SEGMENT_SIZE), BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT,
new WebmExtractor());
@ -192,7 +156,8 @@ public class VideoPlayer extends Activity implements OnClickListener,
updateDebugInfoTextView();
final String userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like"
+ " Gecko) Chrome/38.0.2125.104 Safari/537.36";
DashRendererBuilder rendererBuilder = new DashRendererBuilder(manifestUrl, userAgent, this);
DashRendererBuilder rendererBuilder = new DashRendererBuilder(contentUri.toString(),
userAgent, this);
rendererBuilder.build();
}
@ -269,6 +234,45 @@ public class VideoPlayer extends Activity implements OnClickListener,
return handler;
}
// Permission management methods
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startPlayback();
} else {
Toast.makeText(getApplicationContext(), R.string.storage_permission_denied,
Toast.LENGTH_LONG).show();
finish();
}
}
/**
* Checks whether it is necessary to ask for permission to read storage. If necessary, it also
* requests permission.
*
* @return true if a permission request is made. False if it is not necessary.
*/
@TargetApi(23)
private boolean maybeRequestPermission() {
if (requiresPermission(contentUri)) {
requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE}, 0);
return true;
} else {
return false;
}
}
@TargetApi(23)
private boolean requiresPermission(Uri uri) {
return Util.SDK_INT >= 23 && Util.isLocalFileUri(uri)
&& checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED;
}
// Internal methods
private void stopPlayback() {
if (player != null) {
player.stop();
@ -277,7 +281,7 @@ public class VideoPlayer extends Activity implements OnClickListener,
}
}
private void toggleControlsVisibility() {
private void toggleControlsVisibility() {
if (mediaController != null && player != null) {
if (mediaController.isShowing()) {
mediaController.hide();
@ -295,7 +299,7 @@ public class VideoPlayer extends Activity implements OnClickListener,
debugInfoText.append(
getString(R.string.libopus_version, LibopusAudioTrackRenderer.getLibopusVersion()));
debugInfoText.append("\n");
debugInfoText.append(getString(R.string.current_path, filename));
debugInfoText.append(getString(R.string.current_path, contentUri.toString()));
debugInfoText.append(" ");
debugInfoText.append(debugInfo);
debugInfoText.append(" ");

View file

@ -18,6 +18,7 @@ package com.google.android.exoplayer.demo.vp9opus;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -41,9 +42,6 @@ public class SampleChooserActivity extends Activity {
ListView sampleList = (ListView) findViewById(R.id.sample_list);
final SampleAdapter sampleAdapter = new SampleAdapter(this);
sampleAdapter.add(new Header("Local VP9 Video only"));
sampleAdapter.add(new Sample("S/W Color Conversion - upto 720p", false));
sampleAdapter.add(new Sample("OpenGL", true));
sampleAdapter.add(new Header("DASH - VP9 Only"));
sampleAdapter.add(new Sample("Google Glass",
"http://demos.webmproject.org/dash/201410/vp9_glass/manifest_vp9.mpd"));
@ -67,9 +65,9 @@ public class SampleChooserActivity extends Activity {
}
private void onSampleSelected(Sample sample) {
Intent playerIntent = new Intent(this, VideoPlayer.class)
.putExtra(VideoPlayer.DASH_MANIFEST_URL_ID_EXTRA, sample.uri)
.putExtra(VideoPlayer.USE_OPENGL_ID_EXTRA, sample.useOpenGL);
Intent playerIntent = new Intent(this, PlayerActivity.class)
.setData(Uri.parse(sample.uri))
.putExtra(PlayerActivity.USE_OPENGL_ID_EXTRA, sample.useOpenGL);
startActivity(playerIntent);
}

View file

@ -40,33 +40,14 @@
</com.google.android.exoplayer.AspectRatioFrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#88000000">
<LinearLayout
android:id="@+id/buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/choose_file"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choose_file"/>
<Button
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/play"/>
</LinearLayout>
<TextView
android:id="@+id/debug_info"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/path"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -28,5 +28,6 @@
<string name="libopus_version">
Libopus: <xliff:g id="path">%1$s</xliff:g>
</string>
<string name="storage_permission_denied">Permission to access storage was denied</string>
</resources>