无法播放此视频。由Android设备录制的Android videoView mp4

时间:2014-07-14 05:37:14

标签: java android video video-codecs

enter image description here

我已经与其他formats一起寻找现有的潜在解决方案,并且仍然会回答上述错误。

最后,使用相同的设备录制视频,并将其用作此应用的资源,但仍无效。

设备:SGS2,lenovo a820

视频类型:MPEG-4 video (video/mp4)

    videoView = (VideoView)findViewById(R.id.videoView);
    videoView.setVideoPath("android.resource://raw/sample.mp4");
    videoView.start();

8 个答案:

答案 0 :(得分:12)

只看到我的下面的代码就可以了......在pathe声明中的问题..

 String uriPath = "android.resource://"+getPackageName()+"/"+R.raw.aha_hands_only_cpr_english;
        Uri uri = Uri.parse(uriPath);
        mVideoView.setVideoURI(uri);

多数民众赞成......

答案 1 :(得分:6)

我尝试了之前提到的所有内容,但事实证明,播放mp4文件需要互联网许可。

<uses-permission android:name="android.permission.INTERNET" />

答案 2 :(得分:1)

确保解码器(目标sdk)支持您正在使用的视频格式。您可以使用VLC播放器将视频格式转换为所需的格式。在我的例子中,我将MP4转换为WebM文件并将其加载到VideoView中。

以下是获取文件路径和播放视频的方法。

String path = "android.resource://" + getPackageName() + "/" + R.raw.sample;
VideoView videoView = (VideoView)findViewById(R.id.videoView);
videoView.setVideoURI(Uri.parse(path));
videoView.start()

来源: 视频格式和编解码器支持 https://developer.android.com/guide/topics/media/media-formats.html

答案 3 :(得分:0)

对于Lenovo a820,需要以下内容:

- MP4/WMV/H.264/H.263 player
- MP3/WAV/WMA/eAAC+ player

确保您的视频符合上述编解码格式。

答案 4 :(得分:0)

尝试以下代码..

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();

答案 5 :(得分:0)

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);
    }
}

答案 6 :(得分:0)

只需用以下代码替换您的代码,它将起作用:

sort()

答案 7 :(得分:-1)

尝试以下代码可以正常工作..........

VideoView videoView=(VideoView)findViewById(R.id.videoView);

videoView.setVideoPath("android.resource://"+getPackageName()+"/"+R.raw.videoname;

videoView.start();