Skip to content

Commit

Permalink
Fix Android MediaPlayer Song implementation.
Browse files Browse the repository at this point in the history
Commit 5e918e9 introduced a bug on Android where
song's would not place. This was because it was using
the `name` of the song rather than the `filename`.

Fix up the Android implementation so that it uses the
right field when accessing the audio.
  • Loading branch information
dellis1972 committed Nov 20, 2024
1 parent b27e18d commit f405d2f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions MonoGame.Framework/Platform/Media/Song.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,28 @@ internal void Play(TimeSpan? startPosition)
{
// Prepare the player
_androidPlayer.Reset();


if (assetUri != null)
{
// Check if we have a direct asset URI.
_androidPlayer.SetDataSource(MediaLibrary.Context, this.assetUri);
}
else if (_name.StartsWith("file://"))
else if (_filePath.StartsWith("file://"))
{
// Otherwise, check if this is a file URI.
_androidPlayer.SetDataSource(_name);
_androidPlayer.SetDataSource(_filePath);
}
else
{
// Otherwise, assume it's a file path. (This might throw if the file doesn't exist)
var afd = Game.Activity?.Assets?.OpenFd(_name);
var afd = Game.Activity?.Assets?.OpenFd(_filePath);
if (afd != null)
{
_androidPlayer.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
}
}


_androidPlayer.Prepare();
_androidPlayer.Looping = MediaPlayer.IsRepeating;
_playingSong = this;
Expand Down

0 comments on commit f405d2f

Please sign in to comment.