diff --git a/MediaManager/Media/MediaExtractorBase.cs b/MediaManager/Media/MediaExtractorBase.cs index c7189f0a..01a26e03 100644 --- a/MediaManager/Media/MediaExtractorBase.cs +++ b/MediaManager/Media/MediaExtractorBase.cs @@ -27,7 +27,8 @@ public abstract class MediaExtractorBase : IMediaExtractor public IList ResourcePrefixes { get; } = new List() { "android.resource", - "raw" + "raw", + "assets" }; public IList VideoSuffixes { get; } = new List() { diff --git a/MediaManager/Platforms/Android/Media/MediaExtractor.cs b/MediaManager/Platforms/Android/Media/MediaExtractor.cs index dc01c597..423c9fbf 100644 --- a/MediaManager/Platforms/Android/Media/MediaExtractor.cs +++ b/MediaManager/Platforms/Android/Media/MediaExtractor.cs @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using Android.Content.Res; +using Com.Google.Android.Exoplayer2.Upstream; using MediaManager.Media; namespace MediaManager.Platforms.Android.Media @@ -24,14 +26,41 @@ public override IList CreateProviders() return providers; } - protected override async Task GetResourcePath(string resourceName) + protected override Task GetResourcePath(string resourceName) { string path = null; - using (var stream = MediaManager.Context.Assets.Open(resourceName)) + try { - path = await CopyResourceStreamToFile(stream, "AndroidResources", resourceName).ConfigureAwait(false); + if (int.TryParse(resourceName, out int resourceId)) + { + var rawDataSource = new RawResourceDataSource(MediaManager.Context); + var uri = RawResourceDataSource.BuildRawResourceUri(resourceId); + rawDataSource.Open(new DataSpec(uri)); + path = rawDataSource.Uri.ToString(); + } } - return path; + catch (Exception ex) + { + path = null; + Console.WriteLine(ex.Message); + } + try + { + if (string.IsNullOrEmpty(path)) + { + var assetDataSource = new AssetDataSource(MediaManager.Context); + var dataSpec = new DataSpec(global::Android.Net.Uri.Parse(resourceName)); + assetDataSource.Open(dataSpec); + path = assetDataSource.Uri.ToString(); + } + } + catch (Exception ex) + { + path = null; + Console.WriteLine(ex.Message); + } + + return Task.FromResult(path); } } } diff --git a/MediaManager/Platforms/Ios/Player/IosMediaPlayer.cs b/MediaManager/Platforms/Ios/Player/IosMediaPlayer.cs index d17b5f85..37ce230b 100644 --- a/MediaManager/Platforms/Ios/Player/IosMediaPlayer.cs +++ b/MediaManager/Platforms/Ios/Player/IosMediaPlayer.cs @@ -70,8 +70,9 @@ protected override void Initialize() if (activationError != null) Console.WriteLine("Could not activate audio session {0}", activationError.LocalizedDescription); } - catch + catch (Exception ex) { + Console.WriteLine(ex.Message); } Player.InvokeOnMainThread(() => diff --git a/Samples/ElementPlayer.Android/Assets/assetplay.mp3 b/Samples/ElementPlayer.Android/Assets/assetplay.mp3 new file mode 100644 index 00000000..db9dae3f Binary files /dev/null and b/Samples/ElementPlayer.Android/Assets/assetplay.mp3 differ diff --git a/Samples/ElementPlayer.Android/ElementPlayer.Android.csproj b/Samples/ElementPlayer.Android/ElementPlayer.Android.csproj index 0a2d7054..3b7d0b4a 100644 --- a/Samples/ElementPlayer.Android/ElementPlayer.Android.csproj +++ b/Samples/ElementPlayer.Android/ElementPlayer.Android.csproj @@ -286,6 +286,12 @@ + + + + + +