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

Cast demo not working for HLS #452

Closed
1 task
mohsinDPRO opened this issue Jun 9, 2023 · 14 comments
Closed
1 task

Cast demo not working for HLS #452

mohsinDPRO opened this issue Jun 9, 2023 · 14 comments

Comments

@mohsinDPRO
Copy link

Media3 Version

ExoPlayer 2.18.7

Devices that reproduce the issue

OnePlus 5T, 6, 6T
Android OS - 9, 10, 11, 12, 13

Devices that do not reproduce the issue

None that I know of

Reproducible in the demo app?

Yes

Reproduction steps

  1. Run the demo cast app
  2. Select Clear HLS: Angel one title
  3. the title shows up on the TV, but It fails to play

There are no logs in the console, which I could share

Expected result

Expected result is that the media should start playing on the chromecast device as well.
But apart from HLS rest of the streams are casting to the device, but not the HLS

Actual result

The selected title is shown on the tv screen, even the casting controls show up on the phone from which the casting session was initiated, but the stream does not starts playback on the TV ever

Media

Clear HLS: Angel One - this is the stream from the demo itself, which is not playing

Bug Report

  • You will email the zip file produced by adb bugreport to [email protected] after filing this issue.
@marcbaechinger
Copy link
Contributor

marcbaechinger commented Jun 9, 2023

This is because the cast device or the receiver does not support this HLS stream.

The user here (google/ExoPlayer#11018) says creating your own receiver app solves the problem. I haven't tried that though. I recall trying this out with about 4 different cast devices and it worked on a Next Hub but not on a Chromecast Ultra (first gen). I also think that I was able to play it on an audio only cast device. That's why I think it is device specific.

I don't expect you will use the ExoPlayer receiver app for your app, so doing this would be part of your app anyways. Sorry for not being able to give you a better answer.

@mohsinDPRO
Copy link
Author

Ahh, thanks for the quick reply.
As I understand there would be no other way to make the hls streams cast directly to the chromecast device? Can we not explicity set CORS or user-agent or something, which will help get the hls stream be casted

@mohsinDPRO
Copy link
Author

Hi,
I tried this example at my end on multiple phones and it seems to be casting, just fine,
there must be some changes in the original sdk vs our exoplayer extension, what can we do to debug it?

@marcbaechinger
Copy link
Contributor

Sorry, I'm not sure I understand.

Are you saying the media (Angel one - HLS) plays fine on a Cast device when you are using your app (or another app) that is directly talking to the Cast SDK? And in comparison the same media does not play when you are using the ExoPlayer cast demo app?

Which phone you are using should not make a difference, as it's the cast device that receives just the media URI and then plays on it's own.

What you are saying is that there is a problem in the Cast extension/Cast demo app? If this is the case we certainly need to investigate this.

If the above is correct:
Can you give us some more details about what version of the Cast SDK you are using and what Cast device you made this work with (like the model and if possible version of the software running with this device).

My understanding is that the Cast demo app sends the URI to the device. Sending the URI works from what I remember, but then the media does not play on the cast device.

If you want to debug what is happening on the cast device you can connect a remote Chrome debugger to it. This should give some errors that tell why playing the URI does not work: https://developers.google.com/cast/docs/debugging/remote_debugger

If you do this I would certainly be interested and thankful to hear something back like a stack trace or some log out put from the cast device.

@mohsinDPRO
Copy link
Author

I tried the demo app provided by https://github.com/googlecast/CastVideos-android
The casting here is somehow working with the same chromecast device and phone which I've been using to test the exoplayer cast extension as well.

  • Casting device I am using is chrome cast 1st gen & mi android tv
  • Phones used for testing is OnePlus 3t, 5T, 6, 6T, Samsung Tablet

Can we look into what different are they doing, which we can do to get our extension work

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Jun 10, 2023

I have looked into this a bit more closely as it looks we need to clean up/document some things in the cast demo app.
The matters is quite complicated due to the number of involved components end to end.

For a HLS stream being successfully played on a cast device by the demo app the following components are involved.

  • androidx.media3.cast.CastPlayer: An implementation of androidx.media3.common.Player that translates calls to the Player to calls to the Android Cast SDK.
  • Android Cast SDK: The Cast SDK provides an API for Android to create a sender app. It roughly enables an app to send a media URI and metadata to a remote cast device for playback.
  • Cast receiver app: The cast receiver app is a HTML/JS app that runs on the cast device. It receives the commands form the sender app.
  • Media player: Used by the receiver app and actually plays the media URI (.m3u8 in the case of HLS).
  • Cast device: The cast device provides the media codecs with which the player decodes the media.

Cast demo not working with HLS

For reference the page with the formats supported by the default receiver app that we are using in the demo app.

I have tested 3 HLS streams

with these devices:

  • ChromecastUltra
  • Chromecast Google TV
  • Nest Hub

I tried this with the Media3 cast demo app and with the reference Android sender app that you mentioned.

Test results

The 2 HLS/TS streams play well with any app and on every device.

The Angel One (HLS/MP4) stream didn't play with neither of these devices and with neither of these sender or receiver apps.

On both Chromecast devices with the Media3 demo app, when I tried to play the Angel One stream, the receiver app hung at playback start as you describe. Seeking to another item or similar didn't help to recover. To get out of this state I had to stop casting entirely using the Cast icon top-right.

I was able to play the Angel One stream on all devices with the Shaka player demo from an Android mobile phone.

From all this I'd say that the reason for the Angel One stream failing to play with the Media3 cast demo, is that the media player that is used in the default receiver app can't play HLS/MP4 files. The Shaka demo app uses it's own receiver app with the Shaka media player that explicitly documents support for HLS/MP4.

Choosing a receiver app

Can we look into what different are they doing, which we can do to get our extension work

From what I've seen with the tested HLS streams there is no difference between these two demo sender apps that are using the default receiver app.

I'd focus looking into the receiver app first. A choice that you need to do anyway. You can change the receiver app used by the Media3 cast demo by providing your own OptionsProvider:

public CastOptions getCastOptions(Context context) {
    return new CastOptions.Builder()
        .setReceiverApplicationId(YOUR_RECEIVER_APP_ID)
        // more options
        .build();
  }

Reference your class in the AndroidManifest.xml of the demo app:

<meta-data android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
        android:value="com.example.DemoOptionsProvider"/>

Then test your media with it.

I'm not an expert in that matters, so I can't really give you guidance for this I'm afraid. From the testing above I'd continue looking for a receiver that uses Shaka player if you need HLS/MP4 support.

Changes for Media3

If you, or someone else reading this, know how we can use different metadata or use the SDK API differently to make the Angel One stream work with the default receiver app, then we are interested to hear this. I'm not aware of this.

And lastly, I really don't understand why we are not having a working HLS stream in our demo app, but instead one that is not supported. Sorry for the confusion. Besides, I'm afraid but failing is the expected behavior of playing the Angel One stream with the demo app. We have no plans in changing the receiver app of the cast demo app in the near future.

We keep this as an enhancement:

  • clean up HLS samples in DemoUtil
  • document parts of the above and how to change the receiver app in the demo. Probably in the README of the cast demo.
  • low prio: consider using a receiver supporting HLS/MP4 streams in the cast demo.

@mohsinDPRO
Copy link
Author

Thank you for testing out the sample at your end too.

I went ahead and further did the testing of changing the
The Receiver app id used inside the Exoplayer cast extension is APP_ID_DEFAULT_RECEIVER_WITH_DRM = "A12D4273";
The Receiver app id used inside the Google Cast-Android is APP_ID_DEFAULT_RECEIVER = "CC1AD845";

I tried these on the media3 cast demo Media3 cast demo
And the results I got was the same, where the app kept crashing after casting. This was happening with mp4, dash & hls as well.

But when I tried the same with the example provided by Google Cast-Android the mp4, dash & hls seems to be working fine.

So after all these testing I have come to believe that the issue seems to be in the exoplayer cast extension, where it is crashing the app after the session is established and the playback is just about to start.

I am afraid that even after bulding a receiver app, the problem will be the same as I would still be using the exoplayer cast extension. Can you please share a sample where the exoplayer cast extension is used to cast to any working receiver, which would be playing the stream successfully on the chromecast/tv without crashing the app on phone as well.

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Jun 12, 2023

I have come to believe that the issue seems to be in the exoplayer cast extension,
app kept crashing after casting

Thanks. I have different results based on the testing I did. If the media works on the cast device, the demo app works well.

If you want me to look into this some further, please provide some more details in what exact media URIs you've used, clear repro steps and provide a bug report with the stack traces.

tof-tof pushed a commit that referenced this issue Jun 12, 2023
Issue: #452
#minor-release
PiperOrigin-RevId: 539613535
tof-tof pushed a commit to google/ExoPlayer that referenced this issue Jun 12, 2023
Issue: androidx/media#452
#minor-release
PiperOrigin-RevId: 539613535
@mohsinDPRO
Copy link
Author

Hi Marc,

Following are the steps which I have been following to test the casting extension
Devices used for testing: Chromecast 1st generation, MiTV, OnePlus 6T
Android OS:- 10, 11, 12

Results observed:- casting started on TV, but the app kept crashing when using the exoplayer-cast-extension
Whereas, When I use the same m3u8 url on "Google cast-android" the casting worked just fine.
their demo app also worked just fine.

So I have come to the conclusion that there is an issue with the observer within the exoplayer-cast-extension.

Here is the link to the demo app which I am using which is having the issue:- https://drive.google.com/file/d/1iB17ShL7VG3lu9BMDZC7arL5Lv6ouv8n/view?usp=sharing

Here is the link in which the casting seems to be working just fine:-
https://drive.google.com/file/d/1qLPNRt_uRaOSYW50KwjW9MIaqT9ekrA9/view?usp=sharing

@marcbaechinger
Copy link
Contributor

Please provide complete information as requested in the issue template. The issue template can be found here. If you're unable to share bug reports or test content publicly, please send them to [email protected] using a subject in the format "Issue #1234", where "#1234" should be replaced with your issue number. Please also update this issue to indicate you’ve done this.

icbaker pushed a commit that referenced this issue Jun 15, 2023
#minor-release
Issue: #452
PiperOrigin-RevId: 539915277
icbaker pushed a commit to google/ExoPlayer that referenced this issue Jun 15, 2023
@shaikhmohsink
Copy link

shaikhmohsink commented Jun 19, 2023

Hi Marc,

I went ahead and tried to find the root cause of the crash I was getting after the casting session was active.
Here are my findings, hope full this will help resolve the actual crash in media or exoplayer's cast extension.

I took the example of Google Cast-Android and was able to successfully create the issue that is happening on the exoplayer's cast extension.

And the conclusion that I came to, was the missing images that are to be added to the MediaMetadata object which is wrapped by the MediaInfo and sent to the connected remoteMediaClient.

Here is the piece of code which worked for me, maybe using these changes it could resolve the crashes in the exoplayers cast-exension as well.

public void castVideo(String videoURL, String strTitle) {
        MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
        movieMetadata.putString(MediaMetadata.KEY_TITLE, strTitle);
        movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, "");
        if(playerThumb != null && playerThumb.length() > 0)
            movieMetadata.addImage(new WebImage(Uri.parse(playerThumb+"/"+480+"/"+270)));
        else
            movieMetadata.addImage(new WebImage(Uri.parse("http://via.placeholder.com/5x5")));
        if(playerThumb != null && playerThumb.length() > 0)
            movieMetadata.addImage(new WebImage(Uri.parse(playerThumb+"/"+887+"/"+1200)));
        else
            movieMetadata.addImage(new WebImage(Uri.parse("http://via.placeholder.com/5x5")));
        MediaInfo mediaInfo = new MediaInfo.Builder(videoURL)
                .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                .setContentType("application/x-mpegURL")
                .setMetadata(movieMetadata)
                .build();
        RemoteMediaClient remoteMediaClient = mSessionManager.getCurrentCastSession().getRemoteMediaClient();
        remoteMediaClient.load(new MediaLoadRequestData.Builder().setMediaInfo(mediaInfo).build());
    }

@marcbaechinger
Copy link
Contributor

Thank you!

I'm not sure what your code does differently to what the demo app does:
https://github.com/androidx/media/blob/release/libraries/cast/src/main/java/androidx/media3/cast/DefaultMediaItemConverter.java#L93

these changes it could resolve the crashes in the exoplayers cast-exension as well.

I would be interested to see a stack trace of this crash. I was asking for this already. I'm able to play the media that is in included in the demo app. Can you provide me with a stack trace of the crash you are mentioning. Another way to make this actionable for us, would be to have repro steps with the demo app that explains how this can be reproduced.

tof-tof pushed a commit that referenced this issue Jun 23, 2023
#minor-release
Issue: #452
PiperOrigin-RevId: 539915277
(cherry picked from commit 5afe755)
tof-tof pushed a commit to google/ExoPlayer that referenced this issue Jun 26, 2023
#minor-release
Issue: androidx/media#452
PiperOrigin-RevId: 539915277
(cherry picked from commit 73fda2f)
@google-oss-bot
Copy link
Collaborator

Hey @mohsinDPRO. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Collaborator

Since there haven't been any recent updates here, I am going to close this issue.

@mohsinDPRO if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

tianyif pushed a commit to google/ExoPlayer that referenced this issue Aug 11, 2023
Issue: androidx/media#452
#minor-release
PiperOrigin-RevId: 539613535
(cherry picked from commit 44910cc)
tianyif pushed a commit that referenced this issue Aug 14, 2023
Issue: #452
#minor-release
PiperOrigin-RevId: 539613535
(cherry picked from commit c2f78db)
tianyif pushed a commit to google/ExoPlayer that referenced this issue Aug 14, 2023
Issue: androidx/media#452
#minor-release
PiperOrigin-RevId: 539613535
(cherry picked from commit 44910cc)
@androidx androidx locked and limited conversation to collaborators Sep 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants