Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f4fd3b12
authored
Dec 17, 2018
by
aquilescanta
Committed by
Oliver Woodman
Dec 18, 2018
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Handle failure to get Cast context more gracefully
Issue:#4160 Issue:#4743 PiperOrigin-RevId: 225813243
parent
768f48e1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
0 deletions
demos/cast/src/main/java/com/google/android/exoplayer2/castdemo/MainActivity.java
demos/cast/src/main/res/layout/cast_context_error_message_layout.xml
demos/cast/src/main/res/values/strings.xml
demos/cast/src/main/java/com/google/android/exoplayer2/castdemo/MainActivity.java
View file @
f4fd3b12
...
@@ -41,6 +41,7 @@ import com.google.android.exoplayer2.ui.PlayerView;
...
@@ -41,6 +41,7 @@ import com.google.android.exoplayer2.ui.PlayerView;
import
com.google.android.gms.cast.CastMediaControlIntent
;
import
com.google.android.gms.cast.CastMediaControlIntent
;
import
com.google.android.gms.cast.framework.CastButtonFactory
;
import
com.google.android.gms.cast.framework.CastButtonFactory
;
import
com.google.android.gms.cast.framework.CastContext
;
import
com.google.android.gms.cast.framework.CastContext
;
import
com.google.android.gms.dynamite.DynamiteModule
;
/**
/**
* An activity that plays video using {@link SimpleExoPlayer} and supports casting using ExoPlayer's
* An activity that plays video using {@link SimpleExoPlayer} and supports casting using ExoPlayer's
...
@@ -68,7 +69,20 @@ public class MainActivity extends AppCompatActivity
...
@@ -68,7 +69,20 @@ public class MainActivity extends AppCompatActivity
public
void
onCreate
(
Bundle
savedInstanceState
)
{
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
// Getting the cast context later than onStart can cause device discovery not to take place.
// Getting the cast context later than onStart can cause device discovery not to take place.
try
{
castContext
=
CastContext
.
getSharedInstance
(
this
);
castContext
=
CastContext
.
getSharedInstance
(
this
);
}
catch
(
RuntimeException
e
)
{
Throwable
cause
=
e
.
getCause
();
while
(
cause
!=
null
)
{
if
(
cause
instanceof
DynamiteModule
.
LoadingException
)
{
setContentView
(
R
.
layout
.
cast_context_error_message_layout
);
return
;
}
cause
=
cause
.
getCause
();
}
// Unknown error. We propagate it.
throw
e
;
}
setContentView
(
R
.
layout
.
main_activity
);
setContentView
(
R
.
layout
.
main_activity
);
...
@@ -98,6 +112,10 @@ public class MainActivity extends AppCompatActivity
...
@@ -98,6 +112,10 @@ public class MainActivity extends AppCompatActivity
@Override
@Override
public
void
onResume
()
{
public
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
if
(
castContext
==
null
)
{
// There is no Cast context to work with. Do nothing.
return
;
}
String
applicationId
=
castContext
.
getCastOptions
().
getReceiverApplicationId
();
String
applicationId
=
castContext
.
getCastOptions
().
getReceiverApplicationId
();
switch
(
applicationId
)
{
switch
(
applicationId
)
{
case
CastMediaControlIntent
.
DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
:
case
CastMediaControlIntent
.
DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
:
...
@@ -118,6 +136,10 @@ public class MainActivity extends AppCompatActivity
...
@@ -118,6 +136,10 @@ public class MainActivity extends AppCompatActivity
@Override
@Override
public
void
onPause
()
{
public
void
onPause
()
{
super
.
onPause
();
super
.
onPause
();
if
(
castContext
==
null
)
{
// Nothing to release.
return
;
}
mediaQueueListAdapter
.
notifyItemRangeRemoved
(
0
,
mediaQueueListAdapter
.
getItemCount
());
mediaQueueListAdapter
.
notifyItemRangeRemoved
(
0
,
mediaQueueListAdapter
.
getItemCount
());
mediaQueueList
.
setAdapter
(
null
);
mediaQueueList
.
setAdapter
(
null
);
playerManager
.
release
();
playerManager
.
release
();
...
...
demos/cast/src/main/res/layout/cast_context_error_message_layout.xml
0 → 100644
View file @
f4fd3b12
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018 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"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:id=
"@+id/textView"
android:layout_width=
"0dp"
android:layout_height=
"match_parent"
android:layout_weight=
"1"
android:textSize=
"20sp"
android:gravity=
"center"
android:text=
"@string/cast_context_error"
/>
</LinearLayout>
demos/cast/src/main/res/values/strings.xml
View file @
f4fd3b12
...
@@ -22,4 +22,6 @@
...
@@ -22,4 +22,6 @@
<string
name=
"sample_list_dialog_title"
>
Add samples
</string>
<string
name=
"sample_list_dialog_title"
>
Add samples
</string>
<string
name=
"cast_context_error"
>
Failed to get Cast context. Try updating Google Play Services and restart the app.
</string>
</resources>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment