我正在尝试在VideoView
上播放来自该设备的视频。下面是我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vView = (VideoView) findViewById(R.id.videoView);
mc = new MediaController(this);
vView.setMediaController(mc);
String new_emulator_path = "/storage/emulated/0/Download/testvid.mp4";
Uri uri = Uri.parse(new_emulator_path);
vView.setVideoURI(uri);
vView.requestFocus();
mc.show();
vView.start();
}
..。
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/videoView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true" />
当在5.1上使用相同的代码时,它可以正常播放,但在4.3和更低版本中不能播放。以下是日志摘录:
04-30 00:28:09.141 2293-2293/com.ebook.video D/MediaPlayer: getMetadata
04-30 00:28:09.249 2293-2314/com.ebook.video E/MediaPlayer: error (1, -2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video E/MediaPlayer: Error (1,-2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video D/VideoView: Error: 1,-2147483648
我看过很多关于这个错误代码的帖子,但是我不能理解任何解释。
编辑:我试过播放不同格式的视频- mkv (H264 mpeg-4avc),3gp (H263),mp4 (H264 mpeg-4avc),flv (FLV1)。具有3gp扩展名和H263格式的视频可以正常播放,而其他格式的视频则会显示上述错误消息。有什么办法解决这个问题吗?
发布于 2016-04-30 08:36:06
根据Documentation的说法,安卓在安卓5.1之前不支持H265,所以我认为你对此有问题。您可以使用ExoPlayer (或者以更好的方式围绕VideoPlayer &ExoPlayer使用简单的包装器)。
顺便说一句,使用下面的代码可能会对你有所帮助:
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
videoView.setVideoPath(YOUR_LOCAL_FILE_PATH);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Log.i(TAG,"Hoooray");
}
});
videoView.start();
正如我从你的代码中发现的,你想要在模拟器中显示视频,所以首先看看this相关的文章。
https://stackoverflow.com/questions/36950864
复制