RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
224 stars 27 forks source link

[Android] Caching feature does not work #1911

Open dw8869 opened 1 week ago

dw8869 commented 1 week ago

Caching not wokring on Android.

  1. Call AddMediaToCache
  2. Check GetCachedMediaStatus
  3. Progress value does not increase.
Chris-RH commented 6 days ago
  1. Is it reproducible in a new project with just AVPro Video?
  2. Are you using the Exoplayer API?
  3. What media are you trying to cache?
  4. Can you send us a URL that you have used for testing. Either here or to unitysupport@renderheads.com
  5. Can you provide a full logcat in txt form
dw8869 commented 6 days ago
  1. Yes.
  2. Yes. Caching feature only supported when using the ExoPlayer API.
  3. HLS Media.
  4. https://mediapoccdn2-standard-ms-ams.azureedge.net/44b022b1-9a02-438e-a511-bbae448e8259/bd72fbdb-f539-4f0e-ac99-4fb69242.ism/manifest(audio-only=false,format=m3u8-aapl-v3).m3u8
  5. logcat2.txt

It worked fine with AVProVideo v2.9.x. Here is my test code on DemoScene.

private IEnumerator Start()
{
    // wait for create player.Cache.
    while (player.Cache is null)
    {
        yield return null;
    }

    player.Cache.AddMediaToCache(url);
    player.OpenMedia(new MediaPath(url, MediaPathType.AbsolutePathOrURL), true);
}

public void Update()
{
    if (player != null && player.Cache != null)
    {
        float progress = 0f;
        var status = player.Cache.GetCachedMediaStatus(url, ref progress);
        Debug.Log($"GetCachedMediaStatus: {status} / {progress}");
    }
}
Ste-RH commented 5 days ago

Thanks for reporting this.

We will have this fixed in the next release (v3.0.5).

If you wish to apply a fix to your current working copy of the asset, then you can simply modify some script code...

NOTE: This script change will break iOS caching. Naturally they will both be in a working state for the next build we release.

image

#if !UNITY_EDITOR && ( UNITY_IOS || UNITY_ANDROID )
    // Media Caching
    public sealed partial class PlatformMediaPlayer
    {
        public override bool IsMediaCachingSupported()
        {
            return true;
        }

        public override void AddMediaToCache(string url, string headers, MediaCachingOptions options)
        {
            Native.MediaCachingOptions nativeOptions = new Native.MediaCachingOptions();
            GCHandle artworkHandle = new GCHandle();

            if (options != null)
            {
                nativeOptions.minimumRequiredBitRate = options.minimumRequiredBitRate;
                nativeOptions.minimumRequiredResolution_width = options.minimumRequiredResolution.x;
                nativeOptions.minimumRequiredResolution_height = options.minimumRequiredResolution.y;
                nativeOptions.title = options.title;
                if (options.artwork != null && options.artwork.Length > 0)
                {
                    artworkHandle = GCHandle.Alloc(options.artwork, GCHandleType.Pinned);
                    nativeOptions.artwork = artworkHandle.AddrOfPinnedObject();
                    nativeOptions.artworkLength = options.artwork.Length;
                }
            }

            Native.AVPPluginCacheMediaForURL(_player, url, headers, nativeOptions);

            if (artworkHandle.IsAllocated)
            {
                artworkHandle.Free();
            }
        }

        public override void CancelDownloadOfMediaToCache(string url)
        {
            Native.AVPPluginCancelDownloadOfMediaForURL(_player, url);
        }

        public override void RemoveMediaFromCache(string url)
        {
            Native.AVPPluginRemoveCachedMediaForURL(_player, url);
        }

            public override CachedMediaStatus GetCachedMediaStatus(string url, ref float progress)
            {
            return (CachedMediaStatus)Native.AVPPluginGetCachedMediaStatusForURL(_player, url, ref progress);
            }
    }
#endif

image

    [DllImport(PluginName)]
    public static extern void AVPPluginCacheMediaForURL(IntPtr player, string url, string headers, MediaCachingOptions options);

    [DllImport(PluginName)]
    public static extern void AVPPluginCancelDownloadOfMediaForURL(IntPtr player, string url);

    [DllImport(PluginName)]
    public static extern void AVPPluginRemoveCachedMediaForURL(IntPtr player, string url);

    [DllImport(PluginName)]
    public static extern int AVPPluginGetCachedMediaStatusForURL(IntPtr player, string url, ref float progress);
dw8869 commented 5 days ago

Wow, thank you so much. I'll test it.

dw8869 commented 5 days ago

@Ste-RH I tested your code, caching is works fine. But, does not received FirstFrameReady.

Chris-RH commented 2 days ago

AVPro Video version 3.0.5 has been released. Please let us know if it has not fixed your issue.