Skip to content

Commit

Permalink
r2.14.0 demos
Browse files Browse the repository at this point in the history
* 5-rtsp-barebones-issue-8994
  - added (unofficial)
  - illustrates the fatal error in the RTSP library
    that causes the app to force close,
    as described by ExoPlayer issue 8994
      google/ExoPlayer#8994
  • Loading branch information
warren-bank committed Jun 2, 2021
1 parent 2b4a077 commit 6b43260
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 5-rtsp-barebones-issue-8994/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apply from: '../constants.gradle'
apply plugin: 'com.android.application'

android {
compileSdkVersion project.ext.compileSdkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
versionName project.ext.releaseVersion
versionCode project.ext.releaseVersionCode
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion
}

buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles = [
"proguard-rules.txt",
getDefaultProguardFile('proguard-android.txt')
]
}
debug {
jniDebuggable = true
}
}

lintOptions {
disable 'GoogleAppIndexingWarning','MissingTranslation'
}
}

dependencies {
implementation 'com.google.android.exoplayer:exoplayer-core:' + project.ext.releaseVersion // (1.3 MB) https://mvnrepository.com/artifact/com.google.android.exoplayer/exoplayer-core?repo=scijava-public
implementation 'com.google.android.exoplayer:exoplayer-rtsp:' + project.ext.releaseVersion // (101 KB) https://mvnrepository.com/artifact/com.google.android.exoplayer/exoplayer-rtsp?repo=scijava-public
implementation 'com.google.android.exoplayer:exoplayer-ui:' + project.ext.releaseVersion // (433 KB) https://mvnrepository.com/artifact/com.google.android.exoplayer/exoplayer-ui?repo=scijava-public
}

apply plugin: 'com.google.android.gms.strict-version-matcher-plugin'
3 changes: 3 additions & 0 deletions 5-rtsp-barebones-issue-8994/proguard-rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-keep class com.google.android.exoplayer2.** { *; }

-dontwarn com.google.android.exoplayer2.**
41 changes: 41 additions & 0 deletions 5-rtsp-barebones-issue-8994/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 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.
-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.google.android.exoplayer2.rtspdemo_8994">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:label="@string/application_name"
android:icon="@mipmap/ic_launcher"
android:largeHeap="true"
android:allowBackup="false">

<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (C) 2020 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.rtspdemo_8994;

import android.app.Activity;
import android.os.Bundle;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.rtsp.RtspMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.util.Util;

public final class MainActivity extends Activity {

private static final String TAG = "MainActivity";

private static final String RTSP_MEDIA_URI = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_175k.mov";
private static final String RTSP_MIME_TYPE = "application/x-rtsp";

private PlayerView playerView;
private SimpleExoPlayer player;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
playerView = findViewById(R.id.player_view);
}

@Override
public void onStart() {
super.onStart();
if (Util.SDK_INT > 23) {
initializePlayer();
if (playerView != null) {
playerView.onResume();
}
}
}

@Override
public void onResume() {
super.onResume();
if (Util.SDK_INT <= 23 || player == null) {
initializePlayer();
if (playerView != null) {
playerView.onResume();
}
}
}

@Override
public void onPause() {
super.onPause();
if (Util.SDK_INT <= 23) {
if (playerView != null) {
playerView.onPause();
}
releasePlayer();
}
}

@Override
public void onStop() {
super.onStop();
if (Util.SDK_INT > 23) {
if (playerView != null) {
playerView.onPause();
}
releasePlayer();
}
}

private void initializePlayer() {
SimpleExoPlayer player = new SimpleExoPlayer.Builder(getApplicationContext()).build();

MediaItem mediaItem = new MediaItem.Builder().setUri(RTSP_MEDIA_URI).setMimeType(RTSP_MIME_TYPE).build();
MediaSource mediaSource = (MediaSource) new RtspMediaSource.Factory().createMediaSource(mediaItem);

if (playerView != null) {
playerView.setPlayer(player);
}

// this configuration causes fatal error in RTSP library!!
player.setRepeatMode(Player.REPEAT_MODE_ALL);

player.setPlayWhenReady(true);
player.setMediaSource(mediaSource);
player.prepare();

this.player = player;
}

private void releasePlayer() {
if (playerView != null) {
playerView.setPlayer(null);
}

if (player != null) {
player.release();
player = null;
}
}
}
28 changes: 28 additions & 0 deletions 5-rtsp-barebones-issue-8994/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 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.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">

<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</FrameLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions 5-rtsp-barebones-issue-8994/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

<string name="application_name">ExoPlayer</string>

</resources>
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ include ':1-main'
include ':2-cast'
include ':3-gl'
include ':4-rtsp-barebones'
include ':5-rtsp-barebones-issue-8994'

0 comments on commit 6b43260

Please sign in to comment.