Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Video error VideoPlayer on Android

Discussion in 'Audio & Video' started by charcreon, Sep 10, 2019.

  1. charcreon

    charcreon

    Joined:
    May 14, 2013
    Posts:
    5
    I can't play video on android.
    unity 2018.4.1f1
    android 10 (pixel3)

    Code (CSharp):
    1. void Play()
    2. {
    3.     videoPlayer.source = VideoSource.Url;
    4.     var filePath = string.Format("file://{0}/0.mp4", Application.temporaryCachePath);
    5.     videoPlayer.url = filePath;
    6.     Debug.LogFormat("[VideoManager] [Play] filepath:`{0}`", filePath);
    7.  
    8.     videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
    9.     videoPlayer.EnableAudioTrack(0, true);
    10.     videoPlayer.SetTargetAudioSource(0, AudioManager.Instance.VideoAudioSource);
    11.  
    12.     videoPlayer.prepareCompleted += PrepareCompleted;
    13.     videoPlayer.errorReceived += ErrorReceived;
    14.  
    15.     videoPlayer.enabled = true;
    16.     videoPlayer.Prepare();
    17. }
    18.  
    19. void PrepareCompleted(VideoPlayer vp)
    20. {
    21.     vp.prepareCompleted -= PrepareCompleted;
    22.     vp.errorReceived -= ErrorReceived;
    23.     vp.Play();
    24. }
    25.  
    26. void ErrorReceived(VideoPlayer vp, string message)
    27. {
    28.     vp.prepareCompleted -= PrepareCompleted;
    29.     vp.errorReceived -= ErrorReceived;
    30. }
    31.  
    adb logcat
    Code (CSharp):
    1. 09-10 07:54:05.423  1701  1785 I Unity   : [VideoManager] [Play] filepath:`file:///storage/emulated/0/Android/data/com.xxxx.xxxx/cache/0.mp4`
    2. 09-10 07:54:05.423  1701  1785 I Unity   : VideoManager:Play(Int32, Single, Boolean)
    3. 09-10 07:54:05.423  1701  1785 I Unity   :
    4. 09-10 07:54:05.423  1701  1785 I Unity   : (Filename: ./Runtime/Export/Debug.bindings.h Line: 45)
    5. 09-10 07:54:05.423  1701  1785 I Unity   :
    6. 09-10 07:54:05.449  1701  1823 E NdkMediaExtractor: can't create http service
    7. 09-10 07:54:05.449  1701  1823 W Unity   : AndroidVideoMedia: Error opening extractor: -10002
    8. 09-10 07:54:05.449  1701  1823 W Unity   :
    9. 09-10 07:54:05.449  1701  1823 W Unity   : (Filename:  Line: 471)
    10. 09-10 07:54:05.449  1701  1823 W Unity   :
    11.  
    Confirmed that the file exists
    I don't know the error code(-10002)
     
    kanehana likes this.
  2. takahiro-yamada

    takahiro-yamada

    Joined:
    Mar 22, 2016
    Posts:
    2
    me too

    Code (CSharp):
    1. AndroidVideoMedia: Error opening extractor: -10002
    Unity 2018.1.9f2
    Android10 Pixel3a
     
    kanehana likes this.
  3. bkachmar

    bkachmar

    Joined:
    Mar 15, 2013
    Posts:
    35
    I have the same error on my Pixel 3, Android 10.
     
  4. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    95
    Hello! If you can still reproduce the issue on latest releases of Unity, could you please submit a bug report with a minimal reproduction project for this issue and reply in here with the issue ID?
     
  5. Tyler_loni

    Tyler_loni

    Joined:
    Dec 13, 2018
    Posts:
    1
    I have the same issue on android 10. The project worked fine on android 9, upgraded to 10 and now I get:

    E/NdkMediaExtractor: can't create http service
    W/Unity: AndroidVideoMedia: Error opening extractor: -10002



    The video file is stored locally:

    VP = this.GetComponent<VideoPlayer>();
    Internal_Storage_FileName = Path.Combine(Application.persistentDataPath, Video_Name + ".mp4");
    VP.url = Internal_Storage_FileName;


    Pixel 3, Android 10
    Unity 2019.2.0f1
     
  6. unity_TX6jAMiq4wKzUA

    unity_TX6jAMiq4wKzUA

    Joined:
    Apr 1, 2019
    Posts:
    2
    I have the same issue on android 10 (Pixel 3a, Built by Unity 2018.3.12f1)
    Playing movie by streaming works well.
    Handheld.PlayFullScreenMovie works well too.

    Playing movie by VideoPlayer on local storage (temporaryCachePath and persistentDataPath) doesn't work.


    videoPlayer.errorReceived
    reports
    ```
    VideoPlayer cannot play url : file:///....
    Cannot read file.
    ```
     
  7. Un4GivN_X

    Un4GivN_X

    Joined:
    Aug 6, 2014
    Posts:
    5
    Exact same issue here, Unity 2017.4.29f1 (LTS). It is working perfectly fine iOS and Android except Android 10. The video file is accessible at the expected url and I can play it manually.

    Relevant logs:

    10-07 11:19:24.621 14231 14302 E NdkMediaExtractor: can't create http service
    10-07 11:19:24.621 14231 14302 W Unity : AndroidVideoMedia: Error opening extractor: -10002
    10-07 11:19:24.621 14231 14302 W Unity :
    10-07 11:19:24.621 14231 14302 W Unity : (Filename: Line: 524)
    10-07 11:19:24.621 14231 14302 W Unity :

    10-07 11:19:24.672 14231 14274 E Unity : MediaView :: VideoPlayerOnErrorReceived ERROR : VideoPlayer cannot play url : /storage/emulated/0/Android/data/com.privatebundle.id/files/0xfLAYfU.mp4
    10-07 11:19:24.672 14231 14274 E Unity : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    10-07 11:19:24.672 14231 14274 E Unity : UnityEngine.Logger:Log(LogType, Object)
    10-07 11:19:24.672 14231 14274 E Unity :
    10-07 11:19:24.672 14231 14274 E Unity : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/Android/runtime/DebugBindings.gen.cpp Line: 51)


    edit: I reproduced the issue in a very small project. The key is simply to put a valid .mp4 file into Application.persistentDataPath + "/myvideo.mp4". I pasted my file directly in that folder. It works perfectly fine on my galaxy s8+ (android 9.0). Then I tried on Pixel 2 (android 10.0) and I have the exact error above.

    edit 2: I had an idea. At runtime, I load the video file using WWW request.
    - 10-07 15:58:03.143 10661 10683 I Unity : www loaded, , count = 269520

    The byte[] length is correct. Then, I do the following:
    string destinationPath = System.IO.Path.Combine(Application.temporaryCachePath, "temp.mp4");
    File.WriteAllBytes(destinationPath, www.bytes);

    Then I pass the temporaryCachePath URL to the video player. Exact same issue...

    10-07 15:58:03.161 10661 10751 E NdkMediaExtractor: can't create http service
    10-07 15:58:03.162 10661 10751 W Unity : AndroidVideoMedia: Error opening extractor: -10002
    10-07 15:58:03.175 10661 10683 E Unity : VideoOnErrorReceived ERROR: VideoPlayer cannot play url : /storage/emulated/0/Android/data/com.mycompany.videoplayerandroidpie/cache/temp.mp4

    @Domas_L :)
     
    Last edited: Oct 8, 2019
  8. charcreon

    charcreon

    Joined:
    May 14, 2013
    Posts:
    5
    webm(vp8)も同じ問題が発生しました。
    android10でfile:///でアクセス出来なくなっているのが問題だと思います。回避するmanifestが見当たらないので、なんとかしてほしいものです。
    2018.4.1f1~ 2018.4.10f1のすべてで解決されていないのを確認しています。

    The same problem occurred in webm (vp8).
    I think that the problem is that you can not access at file: /// on android10. I don't see any manifests to avoid, so I'd like somehow.
    It has been confirmed that it has not been resolved in all of 2018.4.1f1 to 2018.4.10f1.
     
  9. Un4GivN_X

    Un4GivN_X

    Joined:
    Aug 6, 2014
    Posts:
    5
  10. Un4GivN_X

    Un4GivN_X

    Joined:
    Aug 6, 2014
    Posts:
    5
    Bug reported, id 1189995
    Thank you!
     
    Domas_L likes this.
  11. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    305
    I got the same issue and I tried to use runtime permission request for
    Code (CSharp):
    1. "android.permission.READ_EXTERNAL_STORAGE"
    But the app crashes. If I finally fix this request, will it help at all or we need to wait until VideoPlayer bug fixed?
     
  12. wintermuute

    wintermuute

    Joined:
    May 12, 2017
    Posts:
    9
    I'm experiencing the same issue. Also trying to pass a cached video url to the VideoPlay on a device running Android 10. I know Unity has said this is working per design, but the suggested modification to the Android Manifest has not resolved the issue....
     
  13. danyruibal

    danyruibal

    Joined:
    Sep 13, 2018
    Posts:
    2
    Also experiencing the same issue. Video is not playing on Android Q / Pixel 2 when using a local filesystem url. Remote URLs are working just fine. Permissions are correctly set, and videos are playing on any other device/OS.

    W/Unity: AndroidVideoMedia: Error opening extractor: -10002.

    I also tried to target API 29 and set the new attribute: android:requestLegacyExternalStorage="true", but it didn't help.
     
    wintermuute and Un4GivN_X like this.
  14. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    305
    Just for experiment fixed permissions, set properly but video still can't be player with a same error message. So the only way is to await for bug fix.
     
  15. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    305
    Man, I can't find this bug by provided id. Are you sure it's commited?
     
  16. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    95
    The case is still being processed by the CQA, you will be able to see the bug on the IssueTracker only after it gets processed.
     
  17. wintermuute

    wintermuute

    Joined:
    May 12, 2017
    Posts:
    9
    After digging into the issue more and reading some Android logcats, I'm guessing the issue won't be resolved by setting a certain permission (I've tried a bunch) but is related to the privacy and scoped storage changes Android made in 10/Q. I did a quick test, made a native android plugin using the getExternalFilesDir() command and passing the resulting path the Unity VideoPlayer, but that still results in a -10002 error and the video not playing. I think the issue has to do with how the VideoPlayer uses the URL to retrieve the video from the device. Read more about the Android Q changes here: https://developer.android.com/about/versions/10/privacy/changes

    I would love to hear from someone at Unity regarding this...
     
  18. michaelsorgrr

    michaelsorgrr

    Joined:
    May 30, 2017
    Posts:
    1
    wintermuute likes this.
  19. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    95
    wintermuute likes this.
  20. wintermuute

    wintermuute

    Joined:
    May 12, 2017
    Posts:
    9
    Awesome! Thank you for the update! When can we get a download for Unity 2019.2.11f1? The latest I'm seeing in the Hub and download archive is 2019.2.10.
     
    Domas_L likes this.
  21. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    95
    Unfortunately, it seems that the version is not yet publicly available, so you will have to wait for a week or two until it is released.
     
  22. jovezhougang

    jovezhougang

    Joined:
    Jun 28, 2019
    Posts:
    4
    Build http server in the app

    import android.app.Application;

    import java.io.FileInputStream;

    import fi.iki.elonen.NanoHTTPD;

    public class VideoServer extends NanoHTTPD {

    Application application;

    public VideoServer(Application application, int port) {
    super(port);
    this.application = application;
    }

    @override
    public Response serve(IHTTPSession session) {
    try {
    final FileInputStream inputStream = new FileInputStream(session.getUri());
    return newFixedLengthResponse(Response.Status.OK, "video/mp4", inputStream,
    inputStream.available());
    } catch (Exception e) {
    StringBuilder builder = new StringBuilder();
    builder.append("<!DOCTYPE html><html><body>");
    builder.append("Sorry, Can't Found the page!");
    builder.append("</body></html>\n");
    return newFixedLengthResponse(Response.Status.NOT_FOUND, "text/html", builder
    .toString());
    }
    }
    }
     
  23. jovezhougang

    jovezhougang

    Joined:
    Jun 28, 2019
    Posts:
    4
    ```java
    import android.app.Application;

    import java.io.FileInputStream;

    import fi.iki.elonen.NanoHTTPD;

    public class VideoServer extends NanoHTTPD {

    Application application;

    public VideoServer(Application application, int port) {
    super(port);
    this.application = application;
    }

    @override
    public Response serve(IHTTPSession session) {
    try {
    final FileInputStream inputStream = new FileInputStream(session.getUri());
    return newFixedLengthResponse(Response.Status.OK, "video/mp4", inputStream,
    inputStream.available());
    } catch (Exception e) {
    StringBuilder builder = new StringBuilder();
    builder.append("<!DOCTYPE html><html><body>");
    builder.append("Sorry, Can't Found the page!");
    builder.append("</body></html>\n");
    return newFixedLengthResponse(Response.Status.NOT_FOUND, "text/html", builder
    .toString());
    }
    }
    }
    ```
     
  24. jovezhougang

    jovezhougang

    Joined:
    Jun 28, 2019
    Posts:
    4
    Build http server in the app
     
  25. jovezhougang

    jovezhougang

    Joined:
    Jun 28, 2019
    Posts:
    4
    Build http server in the app
     
  26. shrvnn1993

    shrvnn1993

    Joined:
    Aug 22, 2016
    Posts:
    3
    I tried on Unity 2019.2.11f1 but still it doesn't work there. Though the release notes say that it is fixed.

    Is there any extra code snippet that has to be written to get it work?Like change in function or something.
     
    ErikAndroid likes this.
  27. ErikAndroid

    ErikAndroid

    Joined:
    Jul 4, 2016
    Posts:
    5
    Same problem for me. Not sure how I can fix this.
     
  28. wintermuute

    wintermuute

    Joined:
    May 12, 2017
    Posts:
    9
    The update seems to have fixed the issue I was experiencing. In my case, the issue was how the Unity VideoPlayer was internally handling file getting on Android devices and that method was no longer supported for Android 10/Q. What my app is doing is storing the temporary video file and passing that path to the Unity VideoPlayer which plays the video on a RawImage. So in my case, there was no additional code or function to call, it was just that the way the Video Player was internally handling files needed to be updated. Are you doing something similar to this?
     
  29. ErikAndroid

    ErikAndroid

    Joined:
    Jul 4, 2016
    Posts:
    5
    Im downloading mp4 files from a server and store at the persistentDataPath. I load these files by passing the path to the VideoPlayer and show on a quad mesh. Worked until android 10.
     
    Last edited: Nov 6, 2019
  30. shrvnn1993

    shrvnn1993

    Joined:
    Aug 22, 2016
    Posts:
    3
    Glad that you got it working!
    Can you share the code snippet? Are you using "file://" ahead of the persistent data path of the file?
     
  31. JCereda

    JCereda

    Joined:
    Aug 29, 2019
    Posts:
    3
    Can't play local VideoClip using Video Player on Android, engine version 2018.4.7. Worked fine using 2018.2.12.

    Works fine on Windows build and Editor.

    Tested with Xiaomi Mi 9t and Realwear HMT1.