Skip to content

Commit

Permalink
Merge pull request #8111 from Mindfulplays/android-song
Browse files Browse the repository at this point in the history
Fix Android song unable to find a specified URI
  • Loading branch information
SimonDarksideJ committed Jun 17, 2024
2 parents 9a8f76f + 69bd62c commit 9ec0fed
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions MonoGame.Framework/Platform/Media/Song.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,22 @@ internal void Play(TimeSpan? startPosition)

if (assetUri != null)
{
// Check if we have a direct asset URI.
_androidPlayer.SetDataSource(MediaLibrary.Context, this.assetUri);
}
else if (_name.StartsWith("file:https://"))
{
// Otherwise, check if this is a file URI.
_androidPlayer.SetDataSource(_name);
}
else
{
var afd = Game.Activity.Assets.OpenFd(_name);
if (afd == null)
return;

_androidPlayer.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
// Otherwise, assume it's a file path. (This might throw if the file doesn't exist)
var afd = Game.Activity?.Assets?.OpenFd(_name);
if (afd != null)
{
_androidPlayer.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
}
}


Expand Down

0 comments on commit 9ec0fed

Please sign in to comment.