Can't play this video. Android videoView mp4 recorded by android device
Asked Answered
I

9

23

enter image description here

I've looked for existing potential solutions with other formats and those still responds with mentioned error.

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

Video type: MPEG-4 video (video/mp4)

    videoView = (VideoView)findViewById(R.id.videoView);
    videoView.setVideoPath("android.resource://raw/sample.mp4");
    videoView.start();
Innumerable answered 14/7, 2014 at 5:37 Comment(2)
Check [this][1] thread for the explanation. [1]: #7806761Batty
This answer worked for me: #59883285Metalware
G
19

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...

Gentes answered 14/7, 2014 at 5:48 Comment(2)
try this link: androidexample.com/Play_Video_File_-_Android_Example/… it works for me...Gentes
after this add mVideoView.start();Apothegm
D
12

I tried everything mentioned before but it turns out that internet permission is needed to play a mp4 file.

<uses-permission android:name="android.permission.INTERNET" />
Downfall answered 19/4, 2016 at 11:5 Comment(0)
S
1

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();
Stephainestephan answered 14/7, 2014 at 5:47 Comment(0)
W
1
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);
    }
}
Willock answered 15/2, 2016 at 10:45 Comment(1)
thanx Andrii.. Actually i was getting late for my class.. :-)Willock
F
1

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.

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 support https://developer.android.com/guide/topics/media/media-formats.html

Fahrenheit answered 8/2, 2017 at 2:7 Comment(0)
E
0

For Lenovo a820 ,below is need :

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

make sure that ur video fits in above codec format.

Evapotranspiration answered 14/7, 2014 at 5:44 Comment(0)
E
0

Just Replace your code with this code and it will be working:

VideoView videoView = findViewById(R.id.videoView);
        videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.sample);
        videoView.start();
Ethiopian answered 16/6, 2020 at 0:54 Comment(1)
While this might answer the question, you should edit your answer to include an explanation of how this code block answers the question. This makes your answer much more useful to those who come across the same issue later on.Iconoclasm
M
0

I think the issue is with the device on which we try to play video, sometimes it doesn't support. I tried running it on Linux emulatoe

Mun answered 17/6, 2022 at 7:30 Comment(0)
Q
-1

Try this following code it works..........

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

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

videoView.start();
Quinlan answered 3/1, 2018 at 6:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.