jfversluis / Plugin.Maui.Audio

Plugin.Maui.Audio provides the ability to play audio inside a .NET MAUI application
MIT License
261 stars 46 forks source link

System.Runtime.InteropServices.COMException (0x80004005) #134

Open ALSULTAN opened 1 month ago

ALSULTAN commented 1 month ago

System.Runtime.InteropServices.COMException (0x80004005) at WinRT.ExceptionHelpers.g__Throw|39_0(Int32 hr) at ABI.Windows.Media.Playback.IMediaPlaybackSessionMethods.get_CanSeek(IObjectReference _obj) at Plugin.Maui.Audio.AudioPlayer.Seek(Double position) at Plugin.Maui.Audio.AudioPlayer.Stop()

√ Device Manufacturer: Dell Inc. Name: Vostro 3910 Model: Vostro 3910

√ System OSVersion: 10.0.19045.4894 Platform: WinUI Idiom: Desktop DeviceType: Physical

√ Language Language: ar-SA DateTime: 9/27/2024 12:46:05 PM Numbers: 1234567890 Separators: 123,456.78 Signs: -12 Currency: $1,234,567,890.00

√ Memory RAM Total: 7,881 MB RAM Used: 7,881 MB RAM Usage: 100%

√ CPU Cores: 12

√ Display Resolution: 1920x1080 Refresh: 60 Hz

bijington commented 1 month ago

Can you provide us with a sample of the code that you are using. An explanation of what the issue is and when you are experiencing it?

ALSULTAN commented 1 month ago
using Plugin.Maui.Audio;

namespace ALSULTAN.Media
{
    class Audio
    {
        static IAudioPlayer KitchenBeepPlayer;
        static Stream KitchenBeepFile;
        internal static async Task PlayKitchenBeep()
        {
            if (KitchenBeepPlayer?.IsPlaying == true) return;
            KitchenBeepFile ??= await FileSystem.OpenAppPackageFileAsync("Audio/message_nudge.mp3");
            KitchenBeepPlayer ??= AudioManager.Current.CreatePlayer(KitchenBeepFile);
            KitchenBeepPlayer.Stop(); // Exception here....
            KitchenBeepPlayer.Play();
        }
    }
}
bijington commented 1 month ago

It sounds like the stream your file is in doesn't support seeking. You can check this by calling .CanSeek on your stream and see what it returns.

I think we should be guarding against this anyway though.

ALSULTAN commented 1 month ago

Actually .CanSeek returns true. and your library works fine with this file but sometimes the error occures.

ALSULTAN commented 1 month ago

On Android (Same Code Above):

Plugin.Maui.Audio.FailedToLoadAudioException: Unable to create AVAudioPlayer from data.
   at Plugin.Maui.Audio.AudioPlayer..ctor(Stream audioStream, AudioPlayerOptions audioPlayerOptions)
   at Plugin.Maui.Audio.AudioManager.CreatePlayer(Stream audioStream, AudioPlayerOptions options)
   at ALSULTAN.Media.Audio.PlayKitchenBeep()
bijington commented 1 month ago

Out of interest why are you calling Stop before Play?

ALSULTAN commented 1 month ago

Out of interest why are you calling Stop before Play?

Because the audio maybe playing when the method is called, so stop the playback and start new one

bijington commented 1 month ago

Out of interest why are you calling Stop before Play?

Because the audio maybe playing when the method is called, so stop the playback and start new one

The if statement on the first line of your method means that won't happen. If you remove the Stop call does it still through an exception?