diff --git a/demos/cast/src/main/AndroidManifest.xml b/demos/cast/src/main/AndroidManifest.xml index 8f0aa69e8c..cd2b51513c 100644 --- a/demos/cast/src/main/AndroidManifest.xml +++ b/demos/cast/src/main/AndroidManifest.xml @@ -34,7 +34,6 @@ - diff --git a/demos/cast/src/main/res/values/strings.xml b/demos/cast/src/main/res/values/strings.xml index 503892da27..766e8972d9 100644 --- a/demos/cast/src/main/res/values/strings.xml +++ b/demos/cast/src/main/res/values/strings.xml @@ -16,9 +16,9 @@ - ExoCast Demo + Exo Cast Demo - ExoCast + Cast DRM scheme not supported by this device. diff --git a/demos/ima/build.gradle b/demos/ima/build.gradle index d93d826b67..c32228de28 100644 --- a/demos/ima/build.gradle +++ b/demos/ima/build.gradle @@ -17,22 +17,30 @@ apply plugin: 'com.android.application' android { compileSdkVersion project.ext.compileSdkVersion buildToolsVersion project.ext.buildToolsVersion + defaultConfig { - applicationId "com.google.android.exoplayer2.imademo" minSdkVersion 16 targetSdkVersion project.ext.targetSdkVersion - versionCode 1 - versionName "1.0" } + buildTypes { release { - minifyEnabled false + shrinkResources true + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt') } + debug { + jniDebuggable = true + } + } + + lintOptions { + // The demo app does not have translations. + disable 'MissingTranslation' } } dependencies { - compile 'com.android.support:appcompat-v7:' + supportLibraryVersion compile project(modulePrefix + 'library-core') compile project(modulePrefix + 'library-ui') compile project(modulePrefix + 'extension-ima') diff --git a/demos/ima/src/main/AndroidManifest.xml b/demos/ima/src/main/AndroidManifest.xml index d6dfe4571e..5c6db02417 100644 --- a/demos/ima/src/main/AndroidManifest.xml +++ b/demos/ima/src/main/AndroidManifest.xml @@ -1,21 +1,39 @@ - + + + + + + + + + - + diff --git a/demos/ima/src/main/java/com/google/android/exoplayer2/imademo/DemoPlayer.java b/demos/ima/src/main/java/com/google/android/exoplayer2/imademo/DemoPlayer.java index d127304437..67d96d7f68 100644 --- a/demos/ima/src/main/java/com/google/android/exoplayer2/imademo/DemoPlayer.java +++ b/demos/ima/src/main/java/com/google/android/exoplayer2/imademo/DemoPlayer.java @@ -17,14 +17,15 @@ package com.google.android.exoplayer2.imademo; import android.content.Context; import android.net.Uri; +import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.ext.ima.ImaAdsLoader; -import com.google.android.exoplayer2.ext.ima.ImaAdsMediaSource; import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; import com.google.android.exoplayer2.extractor.ExtractorsFactory; import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.MediaSource; +import com.google.android.exoplayer2.source.ads.AdsMediaSource; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelection; @@ -37,61 +38,69 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.util.Util; /** - * This class deals with ExoPlayer, the IMA plugin, and all video playback. + * Manages the {@link ExoPlayer}, the IMA plugin and all video playback. */ -class DemoPlayer { +/* package */ final class DemoPlayer { - private final ImaAdsLoader mAdsLoader; - private SimpleExoPlayer mPlayer; - private long mContentPosition; + private final ImaAdsLoader adsLoader; - DemoPlayer(Context context) { - String adTag = context.getString(R.string.ad_tag_url); - mAdsLoader = new ImaAdsLoader(context, Uri.parse(adTag)); + private SimpleExoPlayer player; + private long contentPosition; + + public DemoPlayer(Context context) { + String adTag = context.getString(R.string.ad_tag_url); + adsLoader = new ImaAdsLoader(context, Uri.parse(adTag)); + } + + public void init(Context context, SimpleExoPlayerView simpleExoPlayerView) { + // Create a default track selector. + BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); + TrackSelection.Factory videoTrackSelectionFactory = + new AdaptiveTrackSelection.Factory(bandwidthMeter); + TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); + + // Create a player instance. + player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); + + // Bind the player to the view. + simpleExoPlayerView.setPlayer(player); + + // Produces DataSource instances through which media data is loaded. + DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, + Util.getUserAgent(context, context.getString(R.string.application_name))); + + // Produces Extractor instances for parsing the content media (i.e. not the ad). + ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); + + // This is the MediaSource representing the content media (i.e. not the ad). + String contentUrl = context.getString(R.string.content_url); + MediaSource contentMediaSource = new ExtractorMediaSource( + Uri.parse(contentUrl), dataSourceFactory, extractorsFactory, null, null); + + // Compose the content media source into a new AdsMediaSource with both ads and content. + MediaSource mediaSourceWithAds = new AdsMediaSource(contentMediaSource, dataSourceFactory, + adsLoader, simpleExoPlayerView.getOverlayFrameLayout()); + + // Prepare the player with the source. + player.seekTo(contentPosition); + player.prepare(mediaSourceWithAds); + player.setPlayWhenReady(true); + } + + public void reset() { + if (player != null) { + contentPosition = player.getContentPosition(); + player.release(); + player = null; } + } - void init(Context context, SimpleExoPlayerView simpleExoPlayerView) { - // Create a default track selector. - BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); - TrackSelection.Factory videoTrackSelectionFactory = - new AdaptiveTrackSelection.Factory(bandwidthMeter); - TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); - - // Create a simple ExoPlayer instance. - mPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector); - - // Bind the player to the view. - simpleExoPlayerView.setPlayer(mPlayer); - - // Produces DataSource instances through which media data is loaded. - DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, - Util.getUserAgent(context, context.getString(R.string.app_name))); - // Produces Extractor instances for parsing the media data. - ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); - // This is the MediaSource representing the non-ad, content media to be played. - String contentUrl = context.getString(R.string.content_url); - MediaSource contentMediaSource = new ExtractorMediaSource( - Uri.parse(contentUrl), dataSourceFactory, extractorsFactory, null, null); - // Compose the content media source into a new ImaAdMediaSource with both ads and content. - MediaSource mediaSourceWithAds = new ImaAdsMediaSource( - contentMediaSource, - dataSourceFactory, - mAdsLoader, - simpleExoPlayerView.getOverlayFrameLayout()); - // Prepare the player with the source. - mPlayer.seekTo(mContentPosition); - mPlayer.prepare(mediaSourceWithAds); - mPlayer.setPlayWhenReady(true); + public void release() { + if (player != null) { + player.release(); + player = null; } + adsLoader.release(); + } - void reset() { - if (mPlayer != null) { - mContentPosition = mPlayer.getContentPosition(); - mPlayer.release(); - } - } - - void release() { - mAdsLoader.release(); - } } diff --git a/demos/ima/src/main/java/com/google/android/exoplayer2/imademo/MainActivity.java b/demos/ima/src/main/java/com/google/android/exoplayer2/imademo/MainActivity.java index 6cacdf252f..b1e3a53694 100644 --- a/demos/ima/src/main/java/com/google/android/exoplayer2/imademo/MainActivity.java +++ b/demos/ima/src/main/java/com/google/android/exoplayer2/imademo/MainActivity.java @@ -15,43 +15,44 @@ */ package com.google.android.exoplayer2.imademo; +import android.app.Activity; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ui.SimpleExoPlayerView; /** - * Main Activity for the ExoPlayer IMA plugin example. ExoPlayer objects are created by DemoPlayer, - * which this class instantiates. + * Main Activity for the IMA plugin demo. {@link ExoPlayer} objects are created by + * {@link DemoPlayer}, which this class instantiates. */ -public class MainActivity extends AppCompatActivity { +public final class MainActivity extends Activity { - private DemoPlayer mPlayer; - private SimpleExoPlayerView mView; + private SimpleExoPlayerView playerView; + private DemoPlayer player; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main_activity); + playerView = findViewById(R.id.player_view); + player = new DemoPlayer(this); + } - mView = (SimpleExoPlayerView) findViewById(R.id.simpleExoPlayerView); - mPlayer = new DemoPlayer(this); - } + @Override + public void onResume() { + super.onResume(); + player.init(this, playerView); + } - @Override - public void onResume() { - super.onResume(); - mPlayer.init(this, mView); - } + @Override + public void onPause() { + super.onPause(); + player.reset(); + } - @Override - public void onPause() { - super.onPause(); - mPlayer.reset(); - } + @Override + public void onDestroy() { + player.release(); + super.onDestroy(); + } - @Override - public void onDestroy() { - mPlayer.release(); - super.onDestroy(); - } } diff --git a/demos/ima/src/main/res/layout/activity_main.xml b/demos/ima/src/main/res/layout/activity_main.xml deleted file mode 100644 index 180ab3223f..0000000000 --- a/demos/ima/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - diff --git a/demos/cast/src/main/res/values/styles.xml b/demos/ima/src/main/res/layout/main_activity.xml similarity index 71% rename from demos/cast/src/main/res/values/styles.xml rename to demos/ima/src/main/res/layout/main_activity.xml index 1484a68a68..ad5da62f47 100644 --- a/demos/cast/src/main/res/values/styles.xml +++ b/demos/ima/src/main/res/layout/main_activity.xml @@ -13,10 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - - - + diff --git a/demos/ima/src/main/res/mipmap-hdpi/ic_launcher.png b/demos/ima/src/main/res/mipmap-hdpi/ic_launcher.png index cde69bccce..adaa93220e 100644 Binary files a/demos/ima/src/main/res/mipmap-hdpi/ic_launcher.png and b/demos/ima/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/demos/ima/src/main/res/mipmap-hdpi/ic_launcher_round.png b/demos/ima/src/main/res/mipmap-hdpi/ic_launcher_round.png deleted file mode 100644 index 9a078e3e1a..0000000000 Binary files a/demos/ima/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ diff --git a/demos/ima/src/main/res/mipmap-mdpi/ic_launcher.png b/demos/ima/src/main/res/mipmap-mdpi/ic_launcher.png index c133a0cbd3..9b6f7d5e80 100644 Binary files a/demos/ima/src/main/res/mipmap-mdpi/ic_launcher.png and b/demos/ima/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/demos/ima/src/main/res/mipmap-mdpi/ic_launcher_round.png b/demos/ima/src/main/res/mipmap-mdpi/ic_launcher_round.png deleted file mode 100644 index efc028a636..0000000000 Binary files a/demos/ima/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ diff --git a/demos/ima/src/main/res/mipmap-xhdpi/ic_launcher.png b/demos/ima/src/main/res/mipmap-xhdpi/ic_launcher.png index bfa42f0e7b..2101026c9f 100644 Binary files a/demos/ima/src/main/res/mipmap-xhdpi/ic_launcher.png and b/demos/ima/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/demos/ima/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/demos/ima/src/main/res/mipmap-xhdpi/ic_launcher_round.png deleted file mode 100644 index 3af2608a44..0000000000 Binary files a/demos/ima/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ diff --git a/demos/ima/src/main/res/mipmap-xxhdpi/ic_launcher.png b/demos/ima/src/main/res/mipmap-xxhdpi/ic_launcher.png index 324e72cdd7..223ec8bd11 100644 Binary files a/demos/ima/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/demos/ima/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/demos/ima/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/demos/ima/src/main/res/mipmap-xxhdpi/ic_launcher_round.png deleted file mode 100644 index 9bec2e6231..0000000000 Binary files a/demos/ima/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/demos/ima/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/demos/ima/src/main/res/mipmap-xxxhdpi/ic_launcher.png index aee44e1384..698ed68c42 100644 Binary files a/demos/ima/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/demos/ima/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/demos/ima/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/demos/ima/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png deleted file mode 100644 index 34947cd6bb..0000000000 Binary files a/demos/ima/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/demos/ima/src/main/res/values/colors.xml b/demos/ima/src/main/res/values/colors.xml deleted file mode 100644 index 5a077b3a78..0000000000 --- a/demos/ima/src/main/res/values/colors.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - #3F51B5 - #303F9F - #FF4081 - diff --git a/demos/ima/src/main/res/values/strings.xml b/demos/ima/src/main/res/values/strings.xml index 9bf928a6b3..67a7f06f8b 100644 --- a/demos/ima/src/main/res/values/strings.xml +++ b/demos/ima/src/main/res/values/strings.xml @@ -1,5 +1,24 @@ + + - Exo IMA Demo + + Exo IMA Demo + + + diff --git a/demos/ima/src/main/res/values/styles.xml b/demos/ima/src/main/res/values/styles.xml index 705be27764..1c78ad58df 100644 --- a/demos/ima/src/main/res/values/styles.xml +++ b/demos/ima/src/main/res/values/styles.xml @@ -1,11 +1,23 @@ - + + - diff --git a/demos/main/src/main/res/values/strings.xml b/demos/main/src/main/res/values/strings.xml index cc6357c574..b38ccf6e88 100644 --- a/demos/main/src/main/res/values/strings.xml +++ b/demos/main/src/main/res/values/strings.xml @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. --> - ExoPlayer diff --git a/demos/main/src/main/res/values/styles.xml b/demos/main/src/main/res/values/styles.xml index 751a224210..5616bb9869 100644 --- a/demos/main/src/main/res/values/styles.xml +++ b/demos/main/src/main/res/values/styles.xml @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. --> -