bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
1.97k stars 838 forks source link

AudioPlayer.getDuration gives a incorrect duration when playing .m4a files on iOS #1730

Closed xshiwei closed 5 months ago

xshiwei commented 8 months ago

Checklist

Current bug behaviour

在 iOS 上播放本地 (.m4a) 文件时使用 AudioPlayer.getDuration 方法会给出持续时间(以毫秒为单位),该持续时间比曲目的实际持续时间长 2 倍。在 Android 上使用相同的代码和相同的音乐文件会给出正确的持续时间。

由于给出的持续时间不正确,因此播放器的 onPlayerCompletion 事件不会在曲目结束时触发,而是会晚得多。

这可能是由于库错误地读取 iOS 上的 .m4a 文件元数据造成的。

Expected behaviour

Duration should be consistent

Steps to reproduce

  1. Execute flutter run on the code sample
  2. ...
  3. ...

Code sample

Code sample ```dart void main() { } import 'package:audioplayers/audioplayers.dart'; import 'package:flutter/material.dart'; class DebugMediaTestPage extends StatefulWidget { const DebugMediaTestPage({super.key}); @override State createState() => _DebugMediaTestPageState(); } class _DebugMediaTestPageState extends State { late AudioPlayer _youtubeAudio; @override void initState() { super.initState(); _youtubeAudio = AudioPlayer(); _youtubeAudio.eventStream.listen((event) { debugPrint('event: ${event.toString()}'); }); } Future playYoutubeStream() async { await _youtubeAudio.play(UrlSource('https://rr5---sn-i3belnll.googlevideo.com/videoplayback?expire=1702644364&ei=LPZ7Zd33EvuM1d8PtrCy-Ao&ip=199.182.234.20&id=o-AACxtQ6WCufMClTnw5shWgf9KLqJJW9ejkg0NOzncM9R&itag=139&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&gcr=hk&vprv=1&mime=audio%2Fmp4&gir=yes&clen=1004767&dur=164.467&lmt=1633610990078612&keepalive=yes&fexp=24007246&c=ANDROID_TESTSUITE&txp=2311222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cgcr%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AJfQdSswRQIgUQQ_Uv3eJ9X05ka8CzOuu2VmxlzwqAFHjYn3pRVzMp0CIQCoqE7BivyHJYEUtfSCoY1yNd0P5U98GPXIot1vq8SbRA%3D%3D&redirect_counter=1&rm=sn-i3bds76&req_id=53801a152221a3ee&cms_redirect=yes&cmsv=e&ipbypass=yes&mh=jB&mip=58.84.54.80&mm=31&mn=sn-i3belnll&ms=au&mt=1702623697&mv=m&mvi=5&pl=24&lsparams=ipbypass,mh,mip,mm,mn,ms,mv,mvi,pl&lsig=AAO5W4owRQIgUMFgsiJGzB7PjMf84eui6aHsV15dmC5a-gIbM82RYMsCIQCfUKxc_MITE7t2mVn5K8VBCT_s18nlBgOMonP_bIgxiA%3D%3D')); } @override void dispose() { _youtubeAudio.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( body: ListView( children: [ ElevatedButton( onPressed: () { playYoutubeStream(); }, child: const Text('播放YoutubeStream'), ), ], ), ); } } ```

Affected platforms

iOS

Platform details

No response

AudioPlayers Version

5.2.1

Build mode

No response

Audio Files/URLs/Sources

https://rr5---sn-i3belnll.googlevideo.com/videoplayback?expire=1702644364&ei=LPZ7Zd33EvuM1d8PtrCy-Ao&ip=199.182.234.20&id=o-AACxtQ6WCufMClTnw5shWgf9KLqJJW9ejkg0NOzncM9R&itag=139&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&gcr=hk&vprv=1&mime=audio%2Fmp4&gir=yes&clen=1004767&dur=164.467&lmt=1633610990078612&keepalive=yes&fexp=24007246&c=ANDROID_TESTSUITE&txp=2311222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cgcr%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AJfQdSswRQIgUQQ_Uv3eJ9X05ka8CzOuu2VmxlzwqAFHjYn3pRVzMp0CIQCoqE7BivyHJYEUtfSCoY1yNd0P5U98GPXIot1vq8SbRA%3D%3D&redirect_counter=1&rm=sn-i3bds76&req_id=53801a152221a3ee&cms_redirect=yes&cmsv=e&ipbypass=yes&mh=jB&mip=58.84.54.80&mm=31&mn=sn-i3belnll&ms=au&mt=1702623697&mv=m&mvi=5&pl=24&lsparams=ipbypass,mh,mip,mm,mn,ms,mv,mvi,pl&lsig=AAO5W4owRQIgUMFgsiJGzB7PjMf84eui6aHsV15dmC5a-gIbM82RYMsCIQCfUKxc_MITE7t2mVn5K8VBCT_s18nlBgOMonP_bIgxiA%3D%3D

Screenshots

image

Logs

flutter: event: AudioEvent(eventType: AudioEventType.log, duration: null, position: null, logMessage: player status: AVPlayerItemStatus(rawValue: 1), change: NSKeyValueObservedChange<AVPlayerItemStatus>(kind: __C.NSKeyValueChange, newValue: nil, oldValue: nil, indexes: nil, isPrior: false), isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.duration, duration: 0:05:28.934000, position: null, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.prepared, duration: null, position: null, logMessage: null, isPrepared: true)
flutter: event: AudioEvent(eventType: AudioEventType.duration, duration: 0:05:28.934000, position: null, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.position, duration: null, position: 0:00:00.000000, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.position, duration: null, position: 0:00:00.000000, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.position, duration: null, position: 0:00:00.201000, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.position, duration: null, position: 0:00:00.401000, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.position, duration: null, position: 0:00:00.601000, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.position, duration: null, position: 0:00:00.801000, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.position, duration: null, position: 0:00:01.001000, logMessage: null, isPrepared: null)
flutter: event: AudioEvent(eventType: AudioEventType.position, duration: null, position: 0:00:01.201000, logMessage: null, isPrepared: null)
Full Logs ``` my full logs or a link to a gist ``` Flutter doctor: ``` Output of: flutter doctor -v ```

Related issues / more information

376

Working on PR

no way

Gustl22 commented 8 months ago

Hi there, Use https://www.aconvert.com/analyze.html

It states that the file size is 0

xshiwei commented 8 months ago

I extracted these audio addresses from Youtube. It works smoothly on Android, and the duration is increased by 2 times on iOS, and the second half is empty and no sound is playing.

xshiwei commented 8 months ago

Hi there, Use https://www.aconvert.com/analyze.html

It states that the file size is 0

You can run my sample code to see it. If the test link is expired or invalid, please contact me.

Gustl22 commented 5 months ago

As said, the link you provided in your issue description references a source which is empty. Therefore the player cannot work. Plz provide a valid url that also fulfills the requirements in the troubleshooting guide.

github-actions[bot] commented 5 months ago

This issue was closed by the changes-requested bot due to inactivity.

atvbasha commented 5 months ago

@xshiwei did you find any solution ,i am also facing same issue!!