Skip to content

Commit

Permalink
Merge pull request #3 from amellini/master
Browse files Browse the repository at this point in the history
Android local playback issue
  • Loading branch information
BeautifulPilgrim authored Oct 10, 2022
2 parents d742a4b + c99c0da commit 1b94632
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Platforms/Android/MediaPlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,12 @@ private async Task PrepareAndPlayMediaPlayerAsync()
{
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();

await mediaPlayer.SetDataSourceAsync(ApplicationContext, AndroidNet.Uri.Parse(AudioUrl));

await metaRetriever.SetDataSourceAsync(AudioUrl, new Dictionary<string, string>());
var uri = AndroidNet.Uri.Parse(AudioUrl);
await mediaPlayer.SetDataSourceAsync(ApplicationContext, uri);

//If Uri Scheme is not set its a local file so there's no metadata to fetch
if(!string.IsNullOrWhiteSpace(uri.Scheme))
await metaRetriever.SetDataSourceAsync(AudioUrl, new Dictionary<string, string>());

var focusResult = audioManager.RequestAudioFocus(new AudioFocusRequestClass
.Builder(AudioFocus.Gain)
Expand All @@ -348,12 +351,16 @@ private async Task PrepareAndPlayMediaPlayerAsync()
UpdateMediaMetadataCompat(metaRetriever);
StartNotification();

byte[] imageByteArray = metaRetriever.GetEmbeddedPicture();
//if (imageByteArray == null)
// Cover = await BitmapFactory.DecodeResourceAsync(Resources, Resource.Drawable.abc_ab_share_pack_mtrl_alpha); //TODO player_play
//else
if (imageByteArray != null)
Cover = await BitmapFactory.DecodeByteArrayAsync(imageByteArray, 0, imageByteArray.Length);
//Check if there's some metadata
if (metaRetriever != null && !string.IsNullOrWhiteSpace(metaRetriever.ExtractMetadata(MetadataKey.Album)))
{
byte[] imageByteArray = metaRetriever.GetEmbeddedPicture();
//if (imageByteArray == null)
// Cover = await BitmapFactory.DecodeResourceAsync(Resources, Resource.Drawable.abc_ab_share_pack_mtrl_alpha); //TODO player_play
//else
if (imageByteArray != null)
Cover = await BitmapFactory.DecodeByteArrayAsync(imageByteArray, 0, imageByteArray.Length);
}
}
}
catch (Exception ex)
Expand Down

0 comments on commit 1b94632

Please sign in to comment.