Add support for iOS AVAudioSessionCategory in MediaElement #2053
Replies: 10 comments
-
Hi @JamesBodi. We have added the "needs reproduction" label to this issue, which indicates that we cannot take further action. This issue will be closed automatically in 5 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Beta Was this translation helpful? Give feedback.
-
@brminnick I added a project to reproduce this issue. |
Beta Was this translation helpful? Give feedback.
-
Based on my research, The error codes AVFoundationErrorDomain Code=-11800 and NSOSStatusErrorDomain Code=-66637 generally indicate an issue within the AVFoundation framework, used for processing and handling media content in iOS. While these error codes don't provide specific details about the cause of the issue, they do point to a failure in the media playback or processing operation. The AVFoundationErrorDomain Code=-11800 error translates to AVErrorUnknown, which unfortunately means it's a kind of catch-all for various unknown errors within the AVFoundation framework. This lack of specificity makes it challenging to pinpoint the exact cause without further investigation. In one instance discussed in the Apple Developer Forums, a user encountered a similar error when trying to export a video from an iPhone using AVAssetExportSession. The error was linked to issues with accessing or processing media files, especially when these files were located in shared iCloud albums or required specific handling due to their properties or the iOS version. Another discussion on the Apple Developer Forums relates to an error NSOSStatusErrorDomain Code=-16154, which indicates a problem with an XPC connection, often related to media services being reset. This could result in errors like AVErrorMediaServicesWereReset, suggesting that the issue might stem from the underlying media services layer. |
Beta Was this translation helpful? Give feedback.
-
I have continued to research this and eventually just wrote my own audio service in native code. In the process I think I discovered why MediaElement and Plugin.Maui.Audio fail when attempting to playback on any IOS device. If your code looks like this it won't work:
But if your code looks like this it will work:
I am guessing that MediaElement and Plugin.Maui.Audio are using the same base code as they both fail in the same way and have the same author. As my native code audio service is working perfectly I will not be switching back. |
Beta Was this translation helpful? Give feedback.
-
I'm intrigued to know why it's failing for you but not in the sample application, unless have we missed an example. If you have a fix for this bug it would be amazing if you would submit it in via a PR. |
Beta Was this translation helpful? Give feedback.
-
Playback fails only when you try to play on an IOS device. Did anyone ever test that? The fix for me is shown above. You have to create an AVAsset then create the AVPlayerItem using that asset. I found that some example projects out there have one version that uses the NSUrl and others that use AVAsset. I ended up having both versions with one app working and the other not. When I compared the code I found this one key difference. |
Beta Was this translation helpful? Give feedback.
-
I have audio playback working fine in some of my apps although they are loading from a resource rather than a file on disk. |
Beta Was this translation helpful? Give feedback.
-
I have videos loading from a server and the media player works fine in android and windows but does NOT work for me on an iphone (iphone 8 running ios 16.7.5). When I say it doesnt work, I mean there is no sound or video, just a black image that has a play button thats "crossed out" However, I can see youtube videos thru the app tho (that doesnt use mediaplayer, but webview) I really need this bug fixed since this is a show stopper for me. I can provide a video of both the android and ios version running at the same time on actual devices if that helps Here are the packages I have:
|
Beta Was this translation helpful? Give feedback.
-
I have looked at how |
Beta Was this translation helpful? Give feedback.
-
Based on your statement @ne0rrmatrix, I believe this should be considered as a new proposal feature and maybe we should move this to a discussion, since we may need to discuss about it and if there are any implications. @brminnick what do you think? |
Beta Was this translation helpful? Give feedback.
-
Is there an existing issue for this?
Did you read the "Reporting a bug" section on Contributing file?
Current Behavior
MediaElement plays audio on Android simulators and devices, and on IOS simulators, but does not work on IOS devices. Yes, I checked the "silent" switch. I've turned it on and off. I tested on 2 IOS Iphone versions and one IPad - None work.
MediaElement appears to utilize my logging mechanism (NLog) as I am getting the following error in my log:
2024-01-01 14:25:38.7042|WARN|MediaManager|NSConcreteNotification 0x284c84c80 {name = AVPlayerItemFailedToPlayToEndTimeNotification; object = <AVPlayerItem: 0x2888e8c20, asset = <AVURLAsset: 0x284ccd880, URL = file:///var/mobile/Containers/Data/Application/8B4B4CDD-4176-484D-9F8D-295331FDF6FD/Library/Recordings/2024-01-01_13-47-57/audio_data_00.wav>>; userInfo = { AVPlayerItemFailedToPlayToEndTimeErrorKey = "Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not be completed\" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-66637), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x2805d6190 {Error Domain=NSOSStatusErrorDomain Code=-66637 \"(null)\"}}"; }}
I get this error despite never triggering MediaFailed or MediaEnded events. I get the exact same message when trying to play mp3s. What does this error mean?
I also tried exporting audio files to an external/public folder on an IPad to see if they would play - they played just fine. So there is no issue with the encoding of the audio files. I've also tried playing audio via url, via embedding, and audio files created by my app - none will play on IOS devices.
Expected Behavior
I expect audio files to play on actual IOS devices just as they do on IOS simulators.
Steps To Reproduce
See steps in ReadMe file of referenced project... MediaElement stops working once objects from PLugin.Maui.Audio are created.
public MainPage(IAudioManager audioManager)
{
InitializeComponent();
// TODO: MediaElement works until you uncomment the next 2 lines!!
//_audioManager = audioManager;
//_audioRecorder = _audioManager.CreateRecorder();
}
Link to public reproduction project repository
https://github.com/JamesBodi/AudioPlayerTest.git
Environment
Anything else?
No response
Beta Was this translation helpful? Give feedback.
All reactions