我使用videoView从Internet播放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();
}
};
}
它可以在我的模拟器中很好地运行,但在我的android设备中却无法成功。我的targetSdkVersion和compileSdkVersion是28,我的android设备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
答案 0 :(得分:0)
全部删除,只需使用
videoView.setVideoPath(videoUrl);
videoView.start();
答案 1 :(得分: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();
});
});
答案 2 :(得分:0)
我可以通过将其添加到清单清单android:usesCleartextTraffic =“ true”中来解决此问题:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
有关更多信息,请检查此answear https://stackoverflow.com/a/50834600/3433232