Android 9 videoView can't open this video Online video

写了个最简单的 Android 视频播放器,采用 VideoView 控件,播放网络视频时一直报错," can't play this video file ",代码如下:

Uri uri = Uri.parse("http://vfx.mtime.cn/Video/2019/02/08/mp4/190208204943376259.mp4");
videoView.setVideoURI(uri);
videoView.start();

报错信息如下:

2019-03-15 09:11:49.867 26152-26152/com.uitest W/com.uitest: JIT profile information will not be recorded: profile file does not exits.
2019-03-15 09:11:49.873 26152-26152/com.uitest I/chatty: uid=10049(com.uitest) identical 10 lines
2019-03-15 09:11:49.873 26152-26152/com.uitest W/com.uitest: JIT profile information will not be recorded: profile file does not exits.
2019-03-15 09:11:49.915 26152-26152/com.uitest I/InstantRun: starting instant run server: is main process
2019-03-15 09:11:50.088 26152-26152/com.uitest D/OpenGLRenderer: Skia GL Pipeline
2019-03-15 09:11:50.168 26152-26170/com.uitest I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-03-15 09:11:50.168 26152-26170/com.uitest I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-03-15 09:11:50.169 26152-26170/com.uitest I/OpenGLRenderer: Initialized EGL, version 1.4
2019-03-15 09:11:50.169 26152-26170/com.uitest D/OpenGLRenderer: Swap behavior 2
2019-03-15 09:11:50.184 26152-26170/com.uitest D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2019-03-15 09:11:54.270 26152-26152/com.uitest W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@2732a9
2019-03-15 09:11:54.477 26152-26170/com.uitest D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2019-03-15 09:11:54.521 26152-26152/com.uitest W/MediaPlayer: Couldn't open http://vfx.mtime.cn/Video/2019/02/08/mp4/190208204943376259.mp4: java.io.FileNotFoundException: No content provider: http://vfx.mtime.cn/Video/2019/02/08/mp4/190208204943376259.mp4
2019-03-15 09:11:54.521 26152-26152/com.uitest V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService@f158d8c): Cookies: null
2019-03-15 09:11:54.578 26152-26165/com.uitest V/MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager@b0e0224
2019-03-15 09:11:54.580 26152-26165/com.uitest V/MediaHTTPService: makeHTTPConnection(android.media.MediaHTTPService@f158d8c): cookieHandler: java.net.CookieManager@b0e0224 Cookies: null
2019-03-15 09:11:54.594 26152-26165/com.uitest D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-03-15 09:11:55.136 26152-26170/com.uitest W/libEGL: EGLNativeWindowType 0x95077008 disconnect failed
2019-03-15 09:12:24.841 26152-26166/com.uitest E/MediaPlayerNative: error (1, -2147483648)
2019-03-15 09:12:24.842 26152-26152/com.uitest E/MediaPlayer: Error (1,-2147483648)
2019-03-15 09:12:24.842 26152-26152/com.uitest D/VideoView: Error: 1,-2147483648
2019-03-15 09:12:25.037 26152-26170/com.uitest D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000

  运行时,在Android 9 的系统上运行就报错,在虚拟机或者其他低版本Android实体机上面就可以运行,可以排除网络,视频链接的问题,最大可能是Android 9系统的问题。
最有可能出错的错误原因log:

  • java.io.FileNotFoundException: No content provider:
  • No Network Security Config specified, using platform default
    Stack Overflow 上寻找答案,找了很久,可能有的解决办法:
  • Android 8 以后需要用provider 来提供URI 播放在线视频
  • 配置 Network Security Config
    https://stackoverflow.com/questions/42106294/android-media-stream-error-java-io-filenotfoundexception-no-content-provider

我的解决方法:

res/xml/network-security-config.xml:



    
        
            
        
    

AndroidManifest.xml 文件中 application 下新增:

android:networkSecurityConfig="@xml/network_security_config"

然后便可以运行啦,上面一种 provider 还没来得及看,有时间再找找怎么解决。

Android 8 以后感觉坑挺多,写了个 USB 插拔监听器,动态获取插入 U 盘的路径,权限全部给了,但是可以读,不可以写。

你可能感兴趣的:(Android 9 videoView can't open this video Online video)