Gabrielle
Gabrielle

Reputation: 4981

VideoView not working

I tried to open a mp4 video like this :

VideoView myVideoView = new VideoView(this);
myVideoView.setVideoURI(Uri.parse(path[idImage]));
myVideoView.setLayoutParams(new LinearLayout.LayoutParams(
                                            LayoutParams.FILL_PARENT,
                                            LayoutParams.FILL_PARENT));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();

but I don't see nothing on screen. What did I missed?

My xml file looks like this :

<?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" android:background="#000000"
    android:id="@+id/layout_main">

    <ViewFlipper android:id="@+id/details"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
    </ViewFlipper>

    <VideoView android:layout_height="fill_parent"
   android:layout_width="fill_parent" 
   android:id="@+id/VideoView"></VideoView>

</LinearLayout>

Upvotes: 1

Views: 8313

Answers (2)

Nemanja Kovacevic
Nemanja Kovacevic

Reputation: 3560

I know I'm answering an already answered question but it might help someone who lands here by search.

I couldn't get Android's VideoView from API example to play any file, but it was a mistake on my part.

  1. I've type path from the root, example /videoFileName.mp4 and I should have type it with sdcard in between like /sdcard/videoFileName.mp4

  2. My Sony Ercisson Xperia Arc was connected as a usb mass device storage at the same time I was running my app through adb, so internal sd card was unmounted and file could not be found. I've discovered this when I tryed same code on Samsung Galaxy S which behaves differently when connected.

Upvotes: 2

Damian
Damian

Reputation: 8072

You either need to declare a VideoView tag in your layout e.g.

<VideoView android:layout_height="fill_parent"
   android:layout_width="fill_parent" 
   android:id="@+id/VideoView"></VideoView>

and instantiate using:

VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse(path[idImage]);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();

Upvotes: 0

Related Questions