-
Notifications
You must be signed in to change notification settings - Fork 856
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
PlatformException(DarwinAudioError, AVPlayerItem.Status.failed on setSourceUrl, #1546
Comments
Same here. Did you resolve this? This happened to me in iOS 16.0 (physical device) & iOS 16.2 (Simulator) |
Codec _codec = Codec.defaultCodec; |
Thanks for reply. Meanwhile, kindly give me details. Where do I write this? -BELOW IS MY CODE- final audioPlayer = AudioPlayer(); -ERROR BELOW- flutter: ^[[31mAudioPlayers Exception: AudioPlayerException( |
same here. Both on simulator or device, iOS 16.1 & iOS 16.4. ======= ======= |
I think it's apple's bug. audioplayers can do nothing. as a workaround, you can download it before playing. |
I am facing the same issue |
yes looks like this plugin has issues playing asset files |
I faced this problem too with the following situation, and I think this is because ios (or macos as well) has its own codec for audio, which android aacLc may not be equal to apple aacLc (Please correct me if I make a wrong statement). Somehow I changed the encoder method from aacLc to pcm16bit for ios platform (record package mentioned that pcm8bit has been removed in 5.0.0-beta.2, thats why i use pcm16bit). Hope this idea helps. References Original code
New code
|
I am not trying to record any audio I want to play audio from the asset
folder
…On Tue, Aug 1, 2023 at 8:39 AM Karlsson Lui ***@***.***> wrote:
I faced this problem too with the following situation, and I think this is
because ios (or macos as well) has its own codec for audio, which android
aacLc may not be equal to apple aacLc (Please correct me if I make a wrong
statement). Somehow I changed the encoder method from aacLc to pcm16bit for
ios platform (record package mentioned that pcm8bit has been removed in
5.0.0-beta.2, thats why i use pcm16bit). Hope this idea helps.
References
platform: ios
audio source: record: ^4.4.4
audio player: audioplayers: ^4.0.1
Original code
final Record _recorder = Record();
AudioEncoder encoder = AudioEncoder.aacLc;
await _recorder.start(path: path, encoder: encoder);
New code
final Record _recorder = Record();
AudioEncoder encoder = Platform.isIOS ? AudioEncoder.pcm16bit : AudioEncoder.aacLc;
await _recorder.start(path: path, encoder: encoder);
—
Reply to this email directly, view it on GitHub
<#1546 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AYVJH7QQUYMAOC3ANY4EXB3XTCXCDANCNFSM6AAAAAAZHW5XME>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
For my case, it seems that audioplayers cannot decode the audio bytes in the audio files, may be you can find another audio file from different source and test your code first, if the different source audio file works, you have to convert your audio files to a usable one |
edit your
it works for me |
i solved by renaming path without any space |
This comment was marked as outdated.
This comment was marked as outdated.
@petiibhuzah For local files (here: downloaded files), always use the DeviceFileSource. No need to make an exception for Android (or any other platform) to use UrlSource there...it's not meant to use for local files. |
any work around? I'm facing this in fresh new project (Simulate IP14 but was okay on Web version) |
@lurongshuang it's most likely #1494. And further your code doesn't really make sense: Plz call either:
or
|
# Description - feat: Improved error description for unsupported file formats - fix: Handle white space and special characters in URL and Assets (Web & Darwin) - test: Test files without file extension (not playable Darwin) ## Related Issues Closes #1494 Closes #748 Closes #972 Closes #1546 --------- Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
# Description - feat: Improved error description for unsupported file formats - fix: Handle white space and special characters in URL and Assets (Web & Darwin) - test: Test files without file extension (not playable Darwin) ## Related Issues Closes #1494 Closes #748 Closes #972 Closes #1546 --------- Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com> (cherry picked from commit a4d8442)
you can test this url:https://dict.youdao.com/dictvoice?audio=hobby&type=1 |
@Gustl22 Thanks,after some research,I think avplayer can play a remote audio file through a url without a file extension correctly. In my case, it fails only because it has wrong "content-type", while this link can play successfully: https://dict.youdao.com/dictvoice?audio=hobby&type=2 . it's an mp3 file. |
@Gustl22 this repo based on AVPlayer and AVAssetResourceLoaderDelegate may optimise the way playing a remote audio: |
# Description - feat: Improved error description for unsupported file formats - fix: Handle white space and special characters in URL and Assets (Web & Darwin) - test: Test files without file extension (not playable Darwin) ## Related Issues Closes #1494 Closes #748 Closes #972 Closes #1546 --------- Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
@Mamong We trying to avoid third party implementations, and rather fix the missing contentType ourselfes. It is definitely not that hard, it just needs to be done. I have no Apple environment to properly develop and test, and I also don't have the time at the moment. Feel free to help us out. Let's continue discussion in #803. |
So i stumbled across this error. I know this issue is closed, but this seemed to help. First i had the issue in I thought to myself, weird It works perfectly on android but iOS just dies. Migrated to I said this must be an issue with iOS and the URL im trying to get the file from. For context we are using Strapi as our CMS. So i built this simple method. import 'dart:io';
import 'package:dio/dio.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
Future<File?> downloadMp3(String url) async {
Dio dio = Dio();
Directory tempDir = await getTemporaryDirectory();
String fileName = url.split('/').last; // Extract the file name from the URL
String savePath = '${tempDir.path}/$fileName';
// Check if the file already exists
File file = File(savePath);
if (await file.exists()) {
// File already exists, no need to download again
return file;
}
try {
EasyLoading.show(
status: 'Downloading...',
);
await dio.download(
url,
savePath,
onReceiveProgress: (received, total) {
if (total != -1) {
if (kDebugMode) {
print('${(received / total * 100).toStringAsFixed(0)}%');
}
}
},
);
} catch (e) {
if (kDebugMode) {
print('Error downloading file: $e');
}
EasyLoading.showError('Failed to download file');
return null; // Return null to indicate failure
} finally {
EasyLoading.dismiss();
}
return File(savePath);
}
Then for my playAudio functionality playAudio() async {
try {
if (isPlaying) {
await player.pause();
} else {
await player.stop();
if (Platform.isAndroid) {
await player.play(UrlSource(widget.url));
} else {
var file = await downloadMp3(widget.url);
if (file != null) {
await player.play(DeviceFileSource(file.path));
}
}
}
} catch (e) {
if (kDebugMode) {
print(e);
}
}
} And it works perfectly now. |
Hi, I met same issue, first I used just_audio, but flutter ios keep failing. Now I use audioplayers to try to get ios work. My code is like: // Method to dynamically set a new MediaItem. Can you give me some advice, thanks. |
My code is as follows:
But it still throws the PlatformException(DarwinAudioError, AVPlayerItem.Status.failed on setSourceUrl, Failed to set source. For troubleshooting, see " I have also copied the code from the demo/examples and tried to play the same file as well but no luck with both plugins. If anyone has idea, please guide me. I am totally clueless. |
Some of the problems are probably fixed via #1763 Plz open new issues on problems after this fix, to better separate different causes for the issue. |
It seems you are using item.id ? |
do we have any solution for this? |
This worked for me. Thank you |
Checklist
Current bug behaviour
^[[31mAudioPlayers Exception: AudioPlayerException(
DeviceFileSource(path: /var/mobile/Containers/Data/Application/05BFE1FD-0371-4C27-A279-38645C04E5C3/Library/Caches/recording.aac),
PlatformException(DarwinAudioError, AVPlayerItem.Status.failed on setSourceUrl, null, null)<…>
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(DarwinAudioError, AVPlayerItem.Status.failed on setSourceUrl, null, null)
Expected behaviour
await _player.setSourceDeviceFile(fileUrl);
_player.play(source);
Steps to reproduce
flutter run
on the code sampleCode sample
Affected platforms
iOS
Platform details
Android 正常
ios 报错
AudioPlayers Version
audioplayers: ^4.1.0
Build mode
debug
Audio Files/URLs/Sources
No response
Screenshots
No response
Logs
Full Logs
Flutter doctor:
Related issues / more information
No response
Working on PR
no way
The text was updated successfully, but these errors were encountered: