mirror of
https://github.com/androidx/media.git
synced 2025-05-12 18:19:50 +08:00
Allow launching of ExoPlayer demo app via adb shell.
For example: adb shell am start -a com.google.android.exoplayer.demo.action.VIEW -d http://...
This commit is contained in:
parent
6bf817f107
commit
bcb4ea4f70
@ -41,9 +41,20 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="com.google.android.exoplayer.demo.PlayerActivity"
|
<activity android:name="com.google.android.exoplayer.demo.PlayerActivity"
|
||||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||||
|
android:launchMode="singleInstance"
|
||||||
android:label="@string/application_name"
|
android:label="@string/application_name"
|
||||||
android:theme="@style/PlayerTheme"/>
|
android:theme="@style/PlayerTheme">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="com.google.android.exoplayer.demo.action.VIEW"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:scheme="http"/>
|
||||||
|
<data android:scheme="https"/>
|
||||||
|
<data android:scheme="content"/>
|
||||||
|
<data android:scheme="asset"/>
|
||||||
|
<data android:scheme="file"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
@ -78,13 +78,19 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
|||||||
DemoPlayer.Listener, DemoPlayer.CaptionListener, DemoPlayer.Id3MetadataListener,
|
DemoPlayer.Listener, DemoPlayer.CaptionListener, DemoPlayer.Id3MetadataListener,
|
||||||
AudioCapabilitiesReceiver.Listener {
|
AudioCapabilitiesReceiver.Listener {
|
||||||
|
|
||||||
|
// For use within demo app code.
|
||||||
|
public static final String CONTENT_ID_EXTRA = "content_id";
|
||||||
|
public static final String CONTENT_TYPE_EXTRA = "content_type";
|
||||||
public static final int TYPE_DASH = 0;
|
public static final int TYPE_DASH = 0;
|
||||||
public static final int TYPE_SS = 1;
|
public static final int TYPE_SS = 1;
|
||||||
public static final int TYPE_HLS = 2;
|
public static final int TYPE_HLS = 2;
|
||||||
public static final int TYPE_OTHER = 3;
|
public static final int TYPE_OTHER = 3;
|
||||||
|
|
||||||
public static final String CONTENT_TYPE_EXTRA = "content_type";
|
// For use when launching the demo app using adb.
|
||||||
public static final String CONTENT_ID_EXTRA = "content_id";
|
private static final String CONTENT_EXT_EXTRA = "type";
|
||||||
|
private static final String EXT_DASH = ".mpd";
|
||||||
|
private static final String EXT_SS = ".ism";
|
||||||
|
private static final String EXT_HLS = ".m3u8";
|
||||||
|
|
||||||
private static final String TAG = "PlayerActivity";
|
private static final String TAG = "PlayerActivity";
|
||||||
private static final int MENU_GROUP_TRACKS = 1;
|
private static final int MENU_GROUP_TRACKS = 1;
|
||||||
@ -129,11 +135,6 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
|
||||||
contentUri = intent.getData();
|
|
||||||
contentType = intent.getIntExtra(CONTENT_TYPE_EXTRA, -1);
|
|
||||||
contentId = intent.getStringExtra(CONTENT_ID_EXTRA);
|
|
||||||
|
|
||||||
setContentView(R.layout.player_activity);
|
setContentView(R.layout.player_activity);
|
||||||
View root = findViewById(R.id.root);
|
View root = findViewById(R.id.root);
|
||||||
root.setOnTouchListener(new OnTouchListener() {
|
root.setOnTouchListener(new OnTouchListener() {
|
||||||
@ -185,9 +186,21 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
|||||||
audioCapabilitiesReceiver.register();
|
audioCapabilitiesReceiver.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNewIntent(Intent intent) {
|
||||||
|
releasePlayer();
|
||||||
|
playerPosition = 0;
|
||||||
|
setIntent(intent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
Intent intent = getIntent();
|
||||||
|
contentUri = intent.getData();
|
||||||
|
contentType = intent.getIntExtra(CONTENT_TYPE_EXTRA,
|
||||||
|
inferContentType(contentUri, intent.getStringExtra(CONTENT_EXT_EXTRA)));
|
||||||
|
contentId = intent.getStringExtra(CONTENT_ID_EXTRA);
|
||||||
configureSubtitleView();
|
configureSubtitleView();
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
preparePlayer(true);
|
preparePlayer(true);
|
||||||
@ -597,4 +610,28 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
|||||||
return CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle());
|
return CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a best guess to infer the type from a media {@link Uri} and an optional overriding file
|
||||||
|
* extension.
|
||||||
|
*
|
||||||
|
* @param uri The {@link Uri} of the media.
|
||||||
|
* @param fileExtension An overriding file extension.
|
||||||
|
* @return The inferred type.
|
||||||
|
*/
|
||||||
|
private static int inferContentType(Uri uri, String fileExtension) {
|
||||||
|
String lastPathSegment = !TextUtils.isEmpty(fileExtension) ? "." + fileExtension
|
||||||
|
: uri.getLastPathSegment();
|
||||||
|
if (lastPathSegment == null) {
|
||||||
|
return TYPE_OTHER;
|
||||||
|
} else if (lastPathSegment.endsWith(EXT_DASH)) {
|
||||||
|
return TYPE_DASH;
|
||||||
|
} else if (lastPathSegment.endsWith(EXT_SS)) {
|
||||||
|
return TYPE_SS;
|
||||||
|
} else if (lastPathSegment.endsWith(EXT_HLS)) {
|
||||||
|
return TYPE_HLS;
|
||||||
|
} else {
|
||||||
|
return TYPE_OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user