mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Tweak Demo app code to facilitate overriding Application methods and change the used DataSourceFactory.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=131288634
This commit is contained in:
parent
0b6a93b468
commit
8b3f489bc9
3 changed files with 41 additions and 5 deletions
|
|
@ -29,7 +29,8 @@
|
||||||
android:label="@string/application_name"
|
android:label="@string/application_name"
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:largeHeap="true"
|
android:largeHeap="true"
|
||||||
android:allowBackup="false">
|
android:allowBackup="false"
|
||||||
|
android:name=".DemoApplication">
|
||||||
|
|
||||||
<activity android:name="com.google.android.exoplayer2.demo.SampleChooserActivity"
|
<activity android:name="com.google.android.exoplayer2.demo.SampleChooserActivity"
|
||||||
android:configChanges="keyboardHidden"
|
android:configChanges="keyboardHidden"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.exoplayer2.demo;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placeholder application to facilitate overriding Application methods for debugging and testing.
|
||||||
|
*/
|
||||||
|
public class DemoApplication extends Application {
|
||||||
|
}
|
||||||
|
|
@ -69,6 +69,7 @@ import com.google.android.exoplayer2.ui.KeyCompatibleMediaController;
|
||||||
import com.google.android.exoplayer2.ui.MediaControllerPrevNextClickListener;
|
import com.google.android.exoplayer2.ui.MediaControllerPrevNextClickListener;
|
||||||
import com.google.android.exoplayer2.ui.PlayerControl;
|
import com.google.android.exoplayer2.ui.PlayerControl;
|
||||||
import com.google.android.exoplayer2.ui.SubtitleView;
|
import com.google.android.exoplayer2.ui.SubtitleView;
|
||||||
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
|
||||||
|
|
@ -118,7 +119,7 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
||||||
private Button retryButton;
|
private Button retryButton;
|
||||||
|
|
||||||
private String userAgent;
|
private String userAgent;
|
||||||
private DefaultDataSourceFactory mediaDataSourceFactory;
|
private DataSource.Factory mediaDataSourceFactory;
|
||||||
private SimpleExoPlayer player;
|
private SimpleExoPlayer player;
|
||||||
private MappingTrackSelector trackSelector;
|
private MappingTrackSelector trackSelector;
|
||||||
private TrackSelectionHelper trackSelectionHelper;
|
private TrackSelectionHelper trackSelectionHelper;
|
||||||
|
|
@ -135,7 +136,7 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
userAgent = Util.getUserAgent(this, "ExoPlayerDemo");
|
userAgent = Util.getUserAgent(this, "ExoPlayerDemo");
|
||||||
mediaDataSourceFactory = new DefaultDataSourceFactory(this, userAgent, BANDWIDTH_METER);
|
mediaDataSourceFactory = buildMediaDataSourceFactory();
|
||||||
mainHandler = new Handler();
|
mainHandler = new Handler();
|
||||||
if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
|
if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
|
||||||
CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
|
CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
|
||||||
|
|
@ -338,10 +339,10 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
||||||
: uri.getLastPathSegment());
|
: uri.getLastPathSegment());
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Util.TYPE_SS:
|
case Util.TYPE_SS:
|
||||||
return new SsMediaSource(uri, new DefaultDataSourceFactory(this, userAgent),
|
return new SsMediaSource(uri, buildManifestDataSourceFactory(),
|
||||||
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
|
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
|
||||||
case Util.TYPE_DASH:
|
case Util.TYPE_DASH:
|
||||||
return new DashMediaSource(uri, new DefaultDataSourceFactory(this, userAgent),
|
return new DashMediaSource(uri, buildManifestDataSourceFactory(),
|
||||||
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
|
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
|
||||||
case Util.TYPE_HLS:
|
case Util.TYPE_HLS:
|
||||||
return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger);
|
return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger);
|
||||||
|
|
@ -392,6 +393,16 @@ public class PlayerActivity extends Activity implements OnKeyListener, OnTouchLi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Build a DataSource factory for manifest data, that does not affect the bandwidth estimate. */
|
||||||
|
private DataSource.Factory buildManifestDataSourceFactory() {
|
||||||
|
return new DefaultDataSourceFactory(this, userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Build a DataSource factory for media data, that does affect the bandwidth estimate. */
|
||||||
|
private DataSource.Factory buildMediaDataSourceFactory() {
|
||||||
|
return new DefaultDataSourceFactory(this, userAgent, BANDWIDTH_METER);
|
||||||
|
}
|
||||||
|
|
||||||
// ExoPlayer.EventListener implementation
|
// ExoPlayer.EventListener implementation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue