Baseflow / XamarinMediaManager

Cross platform Xamarin plugin to play and control Audio and Video
https://baseflow.com
MIT License
769 stars 306 forks source link

Cannot play audio from stream in Android #913

Open ikeremozcan opened 8 months ago

ikeremozcan commented 8 months ago

🐛 Bug Report

Can not play audio from stream in Android. This part was working in Xamarin. But in MAUI gives this error

Playback error
[ExoPlayerImplInternal]   com.google.android.exoplayer2.ExoPlaybackException: Unexpected runtime error
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:628)
[ExoPlayerImplInternal]       at android.os.Handler.dispatchMessage(Handler.java:102)
[ExoPlayerImplInternal]       at android.os.Looper.loopOnce(Looper.java:240)
[ExoPlayerImplInternal]       at android.os.Looper.loop(Looper.java:351)
[ExoPlayerImplInternal]       at android.os.HandlerThread.run(HandlerThread.java:67)
[ExoPlayerImplInternal]   Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'com.google.android.exoplayer2.upstream.DataSource com.google.android.exoplayer2.upstream.DataSource$Factory.createDataSource()' on a null object reference
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.source.ProgressiveMediaSource.createPeriod(ProgressiveMediaSource.java:292)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.source.MaskingMediaPeriod.createPeriod(MaskingMediaPeriod.java:128)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.source.MaskingMediaSource.createPeriod(MaskingMediaSource.java:100)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.source.ConcatenatingMediaSource.createPeriod(ConcatenatingMediaSource.java:489)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.source.MaskingMediaPeriod.createPeriod(MaskingMediaPeriod.java:128)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.source.MaskingMediaSource.createPeriod(MaskingMediaSource.java:100)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.MediaSourceList.createPeriod(MediaSourceList.java:315)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.MediaPeriodHolder.createMediaPeriod(MediaPeriodHolder.java:433)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.MediaPeriodHolder.<init>(MediaPeriodHolder.java:108)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.MediaPeriodQueue.enqueueNextMediaPeriodHolder(MediaPeriodQueue.java:190)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.ExoPlayerImplInternal.maybeUpdateLoadingPeriod(ExoPlayerImplInternal.java:1983)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.ExoPlayerImplInternal.updatePeriods(ExoPlayerImplInternal.java:1970)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:968)
[ExoPlayerImplInternal]       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:502)

Expected behavior

Should be able to play meditation from memory stream

Reproduction steps

Play audio file from stream

Stream stream = new MemoryStream(file.Bytes);
await CrossMediaManager.Current.Play(new MediaItem
 {
     Data = stream,
     MediaType = MediaType.Audio,
     MediaLocation = MediaLocation.InMemory,
     MimeType = MediaManager.Media.MimeType.AudioMp3,
});

Configuration

Version: 1.2.2

Platform:

gogolon commented 6 months ago

@ikeremozcan I bumped into the exact same issue. Did you manage to solve it somehow?

ikeremozcan commented 6 months ago

I solve it by saving stream in a file @gogolon. Then play audio from the file

morre95 commented 3 months ago

I have the same problem. I can not get files mp3 to play in android emulator. This line works on windows but not in android for me: await CrossMediaManager.Current.Play("https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3");

I have .net 8 and android 13 I get: Java.Lang.RuntimeException: 'Can't create handler inside thread Thread[Thread-13,10,main] that has not called Looper.prepare()'