我有像
这样的路径文件“文件:///storage/emulated/0/Android/data/com.testcompany.tesapp/files/recs/1234-7896-9076.mp4” videoView.setVideoURI(Uri.parse( “文件:///storage/emulated/0/Android/data/com.testcompany.tesapp/files/recs/1234-7896-9076.mp4”))
播放开始但是我收到了这样的错误
11-10 14:12:30.909: E/MediaPlayer(1022): Error (1,-2147483648)
我搜索了这个错误,并说它是未知的MediaPlayer错误,所以如何避免它。
答案 0 :(得分:1)
使用此代码播放存储中的视频。
Uri vidFile = Uri.parse(
Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/"+"xyz.mp4");
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoURI(vidFile);
videoView.setMediaController(new MediaController(MainActivity.this));
videoView.setVisibility(1);
videoView.bringToFront();
videoView.requestFocus();
videoView.start();
答案 1 :(得分:0)
package com.AnVideoView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class AnVideoView extends Activity {
String SrcPath = "/sdcard/Video/Android in Spaaaaaace!_low.mp4";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoPath(SrcPath);
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<VideoView
android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
使用上面的代码并尝试。简单的代码来播放视频。确定添加了sdcard读写的快照<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
答案 2 :(得分:0)
private void startVideo() {
try{
viv_share_video = (VideoView)findViewById(R.id.viv_share_video);
progressDialog = ProgressDialog.show(PlayVideo.this, "", "Buffering video...", true);
progressDialog.setCancelable(true);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaController mediaController = new MediaController(PlayVideo.this);
mediaController.setAnchorView(viv_share_video);
Uri video = Uri.parse(record_video_path);
viv_share_video.setMediaController(mediaController);
viv_share_video.setVideoURI(video);
viv_share_video.requestFocus();
viv_share_video.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
progressDialog.dismiss();
viv_share_video.start();
}
});
}catch(Exception e){
progressDialog.dismiss();
goBack();
}
}