I tried Addressable Video Playback on Android using following versions:
- Unity 2021.3.9 + Addressables 1.19.19
- Unity 2022.1.16 + Addressables 1.20.5 (This project folder is zipped and attached to this post)
Steps:
-
Use Unity Recorder to record a simple scene with a cube in 1080p as both “H.264 MP4” and “VP8 WebM”.
-
Use the default settings on Addressable Group and use Local cache.
-
Wrote some code to run it:
Code:
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.Video;
public class AddressableVideoTest : MonoBehaviour
{
public AssetReference AssetReference;
public VideoPlayer VideoPlayer;
public TextMeshProUGUI ReportText;
private AsyncOperationHandle<VideoClip> op;
private void Awake()
{
op = AssetReference.LoadAssetAsync<VideoClip>();
op.Completed += Completed;
}
private void Completed( AsyncOperationHandle<VideoClip> result )
{
op.Completed -= Completed;
ReportText.text = op.Result.name + $"[API:{GetAndroidAPILevel()}] -- [Unity:{Application.unityVersion}]";
VideoPlayer.clip = op.Result;
VideoPlayer.Play();
}
private static int GetAndroidAPILevel()
{
#if UNITY_EDITOR
return 29; // Assume Android 10 only for editor use
#endif
string osInfo = SystemInfo.operatingSystem;
return !osInfo.Contains( "Android" ) ? 29 : new AndroidJavaClass("android.os.Build$VERSION").GetStatic<int>("SDK_INT");
}
}
This works fine on Editor as well as any Android Device with API Level 29 or higher (aka Android OS 10.0 or higher). It also works fine on Windows and I am assuming it’ll work on other platforms too.
But when I try to run on any Android device lower than API Level 29 (Android OS 9.0 or lower) then this happens:
Warning:
“Autoconnected Player “Autoconnected Player” AndroidVideoMedia::OpenExtractor could not translate archive:/CAB-156a9f0d16bb33fc9bb9bb792bf6c6ba/CAB-156a9f0d16bb33fc9bb9bb792bf6c6ba.resource to local file. Make sure file exists, is on disk (not in memory) and not compressed.”
“Autoconnected Player “Autoconnected Player” AndroidVideoMedia: Error opening extractor: -10004”
Keeping device connected, the console gets spammed with these 2 separate warnings repeatedly.
This happens for both Unity versions mentioned above and MP4 + WebM formats.
I stumbled upon this documentation that mentioned something at the end:
https://docs.unity3d.com/Packages/com.unity.addressables@1.19/manual/InitializeAsync.html
NOTE
Android applications built with Unity 202.1 or earlier or running on Android 9 or earlier can only play videos from uncompressed AssetBundles. You can use a CacheInitializationSettings object to disable recompression of the cache by disabling the Compress Bundles option.
I think the “Unity 202.1” is a typo and it maybe meant 2021 or earlier. But I have tried this on 2021 and 2022 on their respective most stable current releases.
On Addressable “Default Local Group” where I store the videos, I set it to “Uncompressed” for “Asset Bundle Compression”. I also created CacheInitializationSettings.asset as mentioned on doc and assigned it to, making sure to uncheck “Compress Bundles”.
Absolutely nothing works.
Our mobile game has come to heavily rely on video playback because we use it everywhere for background environments. It allows us to not worry about Scene Optimization and go nuts with effect usage. We are able to playback just fine from Resources folder. But we need to remotely download the videos to Android otherwise APK size will keep getting bigger, hence switch to Addressables. If anyone from the Addressable Unity Team can kindly help us, it would be highly appreciated! We MUST be able to play videos on Android API 28 or lower from Addressable download.
One workaround we have found on a forum is to store the videos with “.bytes” file extension on Addressable group instead of the video format. Then after downloading the .bytes file, the following code converts to mp4 so it can be played like a URL on VideoPlayer component:
Url = Path.Combine(Application.persistentDataPath, videoClipName + ".mp4");
var textAsset = operationHandle.Result;
File.WriteAllBytes( Url, textAsset.bytes);
Addressables.Release( operationHandle );
videoPlayer.url = Url;
But this hack is very dirty as the file becomes exposed in storage directory for Application.persistentDataPath. Anyone can replace/change it as long as filename remains same. Not to mention we have to store every video twice, once as addressable download cache .bytes asset file and once as mp4 in storage. We can erase the addressable cache of course but this is too much overhead to keep track and maintain updates. It also makes the editor workflow a nuisance where the video files cannot even be viewed unless we keep another copy there too with correct extension.
PLEASE HELP!!!
8446601–1120085–Addressable Video Test Project - Unity 2022.zip (1.36 MB)