jfversluis / Plugin.Maui.Audio

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

System.NullReferenceException #138

Open gwise-vision opened 4 hours ago

gwise-vision commented 4 hours ago

App Crash Message: Object reference not set to an instance of an object System.NullReferenceException StreamMediaDataSource.android.cs void StreamMediaDataSource.Dispose(bool disposing) StreamMediaDataSource.android.cs in void StreamMediaDataSource.Dispose(bool disposing)

Your source : https://github.com/jfversluis/Plugin.Maui.Audio/blob/94ad09fabf50140b47851ebfa7a416bcb851801a/src/Plugin.Maui.Audio/StreamMediaDataSource.android.cs#L36

As-IS public override void Close() { data.Dispose(); // This App Crash data = Stream.Null; }

protected override void Dispose(bool disposing)
{
    base.Dispose(disposing);

    data.Dispose(); // This App Crash
    data = Stream.Null;
}

To Be ->

     public override void Close()
{
            if (data != null)
            {
                data.Dispose();
                data = Stream.Null;
            }
}

 protected override void Dispose(bool disposing)
{
    base.Dispose(disposing);

            if (data != null)
            {
                data.Dispose();
                data = Stream.Null;
            }
}
bijington commented 1 hour ago

Thanks for this but the more interesting question to answer will why this class is created with a null stream to start with. How are you using the plugin?