Java 无法播放此视频。安卓设备录制的安卓视频查看mp4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24730087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't play this video. Android videoView mp4 recorded by android device
提问by Jacob
I've looked for existing potential solutions with other formats
and those still responds with mentioned error.
我已经与其他formats
人一起寻找现有的潜在解决方案,但那些仍然以提到的错误进行响应。
Finally, recorded the video with the same device and used it as a resource for this app and it still doesn't work.
最后,用同一台设备录制视频,作为这个应用的资源,还是不行。
Devices: SGS2
, lenovo a820
设备:SGS2
、联想a820
Video type: MPEG-4 video (video/mp4)
视频类型: MPEG-4 video (video/mp4)
videoView = (VideoView)findViewById(R.id.videoView);
videoView.setVideoPath("android.resource://raw/sample.mp4");
videoView.start();
采纳答案by Jayesh Khasatiya
Please refer below code snippet...problem was with the path declaration..
请参考下面的代码片段...问题在于路径声明..
String uriPath = "android.resource://"+getPackageName()+"/"+R.raw.aha_hands_only_cpr_english;
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
Thats it...
就是这样...
回答by KOTIOS
For Lenovo a820 ,below is need :
对于联想 a820,以下是需要的:
- MP4/WMV/H.264/H.263 player
- MP3/WAV/WMA/eAAC+ player
make sure that ur video fits in above codec format.
确保您的视频符合上述编解码器格式。
回答by KOTIOS
try following code..
尝试以下代码..
videoView = (VideoView)this.findViewById(R.id.videoView);
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.start();
回答by Arjun Singh
public class videoplayer extends Activity {
private static final String Videos_URL = "*your URI*";
private VideoView myVideoView;
private int position = 0;
private ProgressDialog progressDialog;
private MediaController mediaControls;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the layout from video_main.xml
setContentView(R.layout.activity_main);
if (mediaControls == null) {
mediaControls = new MediaController(this);
}
// Find your VideoView in your video_main.xml layout
myVideoView = (VideoView) findViewById(R.id.videoView);
// Create a progressbar
progressDialog = new ProgressDialog(this);
// Set progressbar title
progressDialog.setTitle("ABCDEFGH");
// Set progressbar message
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
// Show progressbar
progressDialog.show();
try {
Uri video = Uri.parse(Videos_URL);
myVideoView.setVideoURI(video);
myVideoView.setMediaController(mediaControls);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
myVideoView.seekTo(position);
if (position == 0) {
myVideoView.start();
} else {
myVideoView.pause();
}
}
});
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt("Position", myVideoView.getCurrentPosition());
myVideoView.pause();
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
position = savedInstanceState.getInt("Position");
myVideoView.seekTo(position);
}
}
回答by Vol-i
I tried everything mentioned before but it turns out that internet permission is needed to play a mp4 file.
我尝试了之前提到的所有内容,但结果证明播放 mp4 文件需要互联网权限。
<uses-permission android:name="android.permission.INTERNET" />
回答by noahutz
Be sure that the decoder (target sdk) supports the video format you are using. You can use VLC Player to convert video format to the desired one. In my case, I converted the MP4 to WebM file and load it in the VideoView.
确保解码器(目标 sdk)支持您正在使用的视频格式。您可以使用 VLC 播放器将视频格式转换为所需的格式。就我而言,我将 MP4 转换为 WebM 文件并将其加载到 VideoView 中。
Here is how you get the file path and play your video.
以下是获取文件路径和播放视频的方法。
String path = "android.resource://" + getPackageName() + "/" + R.raw.sample;
VideoView videoView = (VideoView)findViewById(R.id.videoView);
videoView.setVideoURI(Uri.parse(path));
videoView.start()
Source: Video format and codec supporthttps://developer.android.com/guide/topics/media/media-formats.html
来源: 视频格式和编解码器支持https://developer.android.com/guide/topics/media/media-formats.html
回答by Sandeep Tile
Try this following code it works..........
试试这个下面的代码它的工作原理......
VideoView videoView=(VideoView)findViewById(R.id.videoView); videoView.setVideoPath("android.resource://"+getPackageName()+"/"+R.raw.videoname; videoView.start();