安卓,VideoView 无法打开在线视频

3

我使用videoView来播放从互联网上下载的mp4文件,但有时无法播放该视频。这是我的代码:

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

private MediaPlayer.OnPreparedListener createOnPreparedListener(){
        return new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.start();
            }
        };
    }

我的模拟器上可以很好地运行,但在我的安卓设备上却没有成功。我的targetSdkVersion和compileSdkVersion是28,我的安卓设备API是android 28,我的模拟器API是23。

以下是logcat:

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

3个回答

1

我可以通过在清单文件中添加 android:usesCleartextTraffic="true" 来解决这个问题:

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

如需更多信息,请查看此答案https://dev59.com/w1cO5IYBdhLWcg3wWgU0#50834600


0

移除所有并只使用

 videoView.setVideoPath(videoUrl);

        videoView.start();

它需要一些时间来缓冲。 - Adil

0
请尝试这个。
 mVideoViewIntro = findViewById(R.id.video_view_intro);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(mVideoViewIntro);
    mVideoViewIntro.setMediaController(mediaController);
    mVideoViewIntro.setVideoURI(Uri.parse("YOURURLGOESHERE"));
    mVideoViewIntro.start();
    mImageViewClose.setOnClickListener(v -> onBackPressed());

    mVideoViewIntro.setOnPreparedListener(mp -> {
        mp.start();
        mp.setOnVideoSizeChangedListener((mp1, arg1, arg2) -> {
            mProgressBar.setVisibility(View.GONE);
            mp1.start();
        });
    });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接