Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CastContext.getSharedInstance(this) is deprecated. #132

Open
kosso opened this issue Aug 4, 2023 · 12 comments
Open

CastContext.getSharedInstance(this) is deprecated. #132

kosso opened this issue Aug 4, 2023 · 12 comments

Comments

@kosso
Copy link

kosso commented Aug 4, 2023

The documentation for Android'd ability to use Casting appears to be out of date.

After adding the line CastContext.getSharedInstance(this); // <--- add this,
Android Studio complains that it is deprecated and that CastContext.getSharedInstance(Context, Executor) should be used.

I have also tried implementing it this way using CastContext.getSharedInstance(getApplicationContext(), Executors.newSingleThreadExecutor() );

but when I try to Cast to an Android TV, the app immediately crashes with :

java.lang.IllegalArgumentException: playPosition can not be negative: -672

For reference, this error is documented here :

https://developers.google.com/android/reference/com/google/android/gms/cast/framework/media/RemoteMediaClient#public-pendingresultremotemediaclient.mediachannelresult-queueinsertandplayitem-mediaqueueitem-item,-int-insertbeforeitemid,-long-playposition,-jsonobject-customdata

The video was playing fine on the device before attempting to Cast.

@kosso
Copy link
Author

kosso commented Aug 4, 2023

Slight update to this regarding the crash when casting: It does appear to work when using a direct MP4 remote URL.

Our use-case is live video using LL-HLS. The player on the device works fine with our remote LIVE url, but crashes when starting a Cast session.

(I also added some test code to prevent the negative player position. I also added an artwork property to the player initialisation which did appear before the Casting client gave up.)

@jepiqueau
Copy link
Collaborator

@PhantomPainX can you please have a look at this issue as you implement the cast part of the plugin

@PhantomPainX
Copy link
Contributor

Hello, sorry for the late. Yeah, I knew about this error and I tried to solve it by implementing the method that Android Studio suggested but I couldn't get it to work and I left it with the old method since that was the only way to make it work.

Tomorrow as I have a little time I'll try to fix it, but I really doubt it 😔

Last thing, this can be obvious, but if you find the solution, please share it with us in a PR 😁🙏

@PhantomPainX
Copy link
Contributor

Ok, I got it to work now. CastContext.getSharedInstance(this); is no longer necessary in MainActivity.java. Plus I have updated these dependencies to last version:

build.gradle (plugin)

  • implementation 'com.google.android.exoplayer:exoplayer-core:2.19.0'
  • implementation 'com.google.android.exoplayer:exoplayer-ui:2.19.0'
  • implementation 'com.google.android.exoplayer:exoplayer-hls:2.19.0'
  • implementation 'com.google.android.exoplayer:exoplayer-dash:2.19.0'
  • implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.19.0'
  • implementation 'com.google.android.exoplayer:extension-mediasession:2.19.0'
  • implementation 'com.google.android.exoplayer:exoplayer:2.19.0'
  • implementation 'com.google.android.exoplayer:extension-cast:2.19.0'

build.gradle (app)

  • implementation 'com.google.android.gms:play-services-cast-framework:21.3.0'

Everything works fine, but with hls videos doesn't work on cast. I tried old-original code and these videos didn't work too, at least with the ones I have.

@kosso can you provide me a functional video from your end to test it tomorrow? (I'm in Chile GMT-3)

@kosso
Copy link
Author

kosso commented Aug 7, 2023

@PhantomPainX Hi there. Thanks for this.

Here's a test stream : https://thisisamazing.tv/live.m3u8

@waltercruz
Copy link

Hi @PhantomPainX! com.google.android.exoplayer2 is deprecated, maybe it's a good idea to migrate to androidx.media3 (it's the same exoplayer, but another imports, etc).

There's a shell script to help with the migration:

https://developer.android.com/guide/topics/media/media3/getting-started/migration-guide

@jepiqueau
Copy link
Collaborator

@waltercruz thanks for providing the info. This will require a complete review of the code. May be the right time to write a complete new code may be in kotlin. This will take some time. Media3 bring a lot of new things which i have first to understand and play with. Anyhow thanks to point it out to us

@waltercruz
Copy link

Sure, I know that these big changes require more time!

Thanks for the plugin @jepiqueau !

@PhantomPainX
Copy link
Contributor

@PhantomPainX Hi there. Thanks for this.

Here's a test stream : https://thisisamazing.tv/live.m3u8

Hey, sorry for not answering sooner, I've been very busy with my job and didn't have time to check the plugin with your video. Short answer, it didn't work. I was investigating and it is because the chromecast devices only support some audio and video codecs. You can check it here: https://developers.google.com/cast/docs/media

So, your video may not be compatible with cast. I think you can transcode it in some backend service and use that source in your application.

In the other hand as I said in my previous reply, I updated the exoplayer dependencies and now I have made some changes like hide the seekbar, progress textview, irrelevant buttons like prev, next, fast forward, rewind and show a LIVE label when the video is live streaming. Should I make a PR for this @jepiqueau @kosso or it is not necessary?

@PhantomPainX
Copy link
Contributor

Hi @PhantomPainX! com.google.android.exoplayer2 is deprecated, maybe it's a good idea to migrate to androidx.media3 (it's the same exoplayer, but another imports, etc).

There's a shell script to help with the migration:

https://developer.android.com/guide/topics/media/media3/getting-started/migration-guide

Yeah, I noticed it when I updated the dependencies, almost everything became obsolete hahaha. I think the best will be to update to media3, but as Jep said, it requires reviewing all the code, the same way if the migration tool is used, since currently the plugin uses many deprecated functions that are not in line with the latest version of ExoPlayer and it is not recommended by the migration documentation.

I'll check this when I have time, thanks for the info 👍

@waltercruz
Copy link

In the other hand as I said in my previous reply, I updated the exoplayer dependencies and now I have made some changes like hide the seekbar, progress textview, irrelevant buttons like prev, next, fast forward, rewind and show a LIVE label when the video is live streaming. Should I make a PR for this @jepiqueau @kosso or it is not necessary?

Hi @PhantomPainX !

I'm interested on the live label! And the updated instructions to chromecast support too, if available.

@waltercruz
Copy link

HI @PhantomPainX !

Just got on the same problem that was reported on this issue, But I think that the problem is not the codec.

Maybe it needs something slightly different on live streams? - (the live offset?)

https://developer.android.com/guide/topics/media/exoplayer/live-streaming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants