f111fei / react-native-unity-view

Show an unity view in react native
MIT License
402 stars 102 forks source link

Why is the Unity Video Player not working? #77

Closed ambisign-gavin closed 5 years ago

ambisign-gavin commented 5 years ago

I need to use Vuforia to play a video when I found a specific target. And my implement way was attaching VideoPlayer to a Plane object. But for now, the Plane attached by VideoPlayer is always a blank, nothing showed.

I alos tried to use the normal Unity project to implement the VideoPlayer, but it is still showing blank. unityvideoplayer

However, it works if I use Unity to build and run apk ,not by react-native . screenshot_2018-12-22-23-12-45

Does anyone have this problem before? I will be grateful for any help you can provide. Thank you!

f111fei commented 5 years ago

Check whether there is an error console. Video components are also used in my project, but it's work.

ambisign-gavin commented 5 years ago

Thanks for replying soon. But I didn't see any error in my console. Did you change any build settings to your project?

P.S. I tested it on Android.

JanOwiesniak commented 5 years ago

My project is based on the demo repo as well and i have worked with the default Unity video components without any problems. Does the video work if you export it as „stand-alone“ XCode / Android Project through the default Build Settings?

ambisign-gavin commented 5 years ago

@JanOwiesniak thanks for your reply.

I have tried many video types, including WebM, MP4, and MOV.

All videos I've tried were played successfully when I exported my Unity project alone with default settings and built it through Android Studio.

But only two videos were played successfully when I built the Unity project as AAR, and imported it to my Android Studio project, or used react-native-unity-view.

One of the successful video format and codec is MOV and H.264 High, and the other one is WebM and VP8. But the weird thing is I have these two formats and codecs in those fail videos too.

That very confuses me, maybe Unity project has different video support rule when it used as a Library?

JanOwiesniak commented 5 years ago

Hm, i tested the default packages only with mp4 files and had no problems. Recently i switched to this package which offers support for many different file formats out of the box and is highly configurable. You could give it a try.

ambisign-gavin commented 5 years ago

Finally, I fixed this problem by add aaptOptions in my build.gradle

android {
    ....
    ....
    aaptOptions {
        noCompress '.unity3d', '.ress', '.resource', '.obb'
    }
    ....
}

And I found a note in Unity docs

Playback from asset bundles is only supported for uncompressed bundles, read directly from disk.

that may be related to this problem, but still can't answer me why some videos can be played, and others can't.

@JanOwiesniak I've tried the AVPro Video package, which is very powerful. I will use it if I need more video features.

Thanks for your help.