ryanheise / just_audio

Audio Player
1.05k stars 671 forks source link

M3U8 url not playing in android devices in flutter #1075

Open jibinjayachandran opened 1 year ago

jibinjayachandran commented 1 year ago

Which API doesn't behave as documented, and how does it misbehave? AudioPlayer.setUrl('https://api.moodstream.anothercircus.com/api/m3u8?mood=4') not working in android device and it gives ExoplaybackException

just_audio: ^0.9.35

Minimal reproduction project

import 'package:just_audio/just_audio.dart';
import 'package:flutter/material.dart';

void main() {
AudioPlayer _player = AudioPlayer();
await _player.setUrl('https://api.moodstream.anothercircus.com/api/m3u8?mood=4');
 _player.play();
}

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Error messages

I/ExoPlayerImpl( 6054): Init 8c47a82 [ExoPlayerLib/2.18.7] [emu64a, sdk_gphone64_arm64, Google, 33] E/ExoPlayerImplInternal( 6054): Playback error E/ExoPlayerImplInternal( 6054):   com.google.android.exoplayer2.ExoPlaybackException: Source error E/ExoPlayerImplInternal( 6054):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:644) E/ExoPlayerImplInternal( 6054):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:614) E/ExoPlayerImplInternal( 6054):       at android.os.Handler.dispatchMessage(Handler.java:102) E/ExoPlayerImplInternal( 6054):       at android.os.Looper.loopOnce(Looper.java:201) E/ExoPlayerImplInternal( 6054):       at android.os.Looper.loop(Looper.java:288) E/ExoPlayerImplInternal( 6054):       at android.os.HandlerThread.run(HandlerThread.java:67) E/ExoPlayerImplInternal( 6054):   Caused by: com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, Mp3Extractor, AviExtractor, JpegExtractor) could read the stream. E/ExoPlayerImplInternal( 6054):       at com.google.android.exoplayer2.source.BundledExtractorsAdapter.init(BundledExtractorsAdapter.java:92) E/ExoPlayerImplInternal( 6054):       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1017) E/ExoPlayerImplInternal( 6054):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412) E/ExoPlayerImplInternal( 6054):       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) E/ExoPlayerImplInternal( 6054):       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) E/ExoPlayerImplInternal( 6054):       at java.lang.Thread.run(Thread.java:1012) E/AudioPlayer( 6054): TYPE_SOURCE: None of the available extractors (FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, Mp3Extractor, AviExtractor, JpegExtractor) could read the stream. I/ExoPlayerImpl( 6054): Release 8c47a82 [ExoPlayerLib/2.18.7] [emu64a, sdk_gphone64_arm64, Google, 33] [goog.exo.core, goog.exo.exoplayer, goog.exo.decoder, goog.exo.datasource, goog.exo.extractor]

Expected behavior The url which I given in the example code works fine in the ios device.the issue is only happening in android device or emulators.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Flutter SDK version

[✓] Flutter (Channel stable, 3.13.4, on macOS 13.4 22F66 darwin-arm64, locale en-AE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.81.1)
[✓] Connected device (3 available)
[✓] Network resources

Additional context Add any other context about the problem here.

jibinjayachandran commented 1 year ago

@ryanheise Could you please help me on this issue I'm facing on android ?

jibinjayachandran commented 1 year ago

I resolved this issue by setting the url as HlsAudioSource and it works fine both in andorid and ios.

await _player.setAudioSource(
          HlsAudioSource(Uri.parse(url)));

but in server , it hits too many times.

217.165.13.115 - - [03/Oct/2023:12:12:59 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:12:59 +0000] "GET /api/track/relay/225.mp3 HTTP/1.1" 302 2458 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:11 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:12 +0000] "GET /api/track/relay/142.mp3 HTTP/1.1" 302 2474 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:12 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:12 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:12 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:13 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:13 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:13 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"
217.165.13.115 - - [03/Oct/2023:12:13:13 +0000] "GET /api/m3u8?mood=4 HTTP/1.1" 200 10820 "-" "just_audio/1.0.0 (Linux;Android 13) ExoPlayerLib/2.18.7"

@ryanheise Could you please suggest me why this is happening and How do I resolve this ?

ryanheise commented 1 year ago

Thanks for doing some exploration. Yes regarding the behaviour of setUrl, it can only try to guess whether it should be HLS by looking at the extension. Since your URL doesn't follow that convention of using an extension in the filename, it fails to guess. So if you are in control of the server, another option (besides directly using HlsAudioSource) is to change the endpoint to something like /api/something.m3u8.

Regarding the server logs, I think that once you're actually getting it to detect that it's HLS, then the plugin uses the native Android or iOS system to play that stream, and in the above case, that is Android's ExoPlayer making all those calls. Maybe you can test other Android apps with the same URL to see if they hit the server in the same way.