简体   繁体   中英

VideoView doesn't work on Android 4.0 and above

I'm creating a VideoView in runtime like this:

@Override
public View getUIElement(){
    if(vv==null){
        this.vv = new VideoView(this.getContext());
        vv.setVideoURI(Uri.parse(this.url));    
        mc = new MediaController(this.getContext());
        vv.setMediaController(mc);  
    }
    return vv;
}

and after that I add this VideoView to LinearLayout I'm calling this:

public void initVideo(){
    mc.show();  
    vv.setBackgroundColor(Color.TRANSPARENT);
    vv.requestFocus();
    vv.start(); 
    Log.v("Video",vv.toString());
}

This code works perfectly on Froyo (2.2) and Gingerbread (2.3.5), but on ICS (4.0) and JB(4.1) nothing happens - VideoView is not even visible in parent View. Do you have any ideas why? In Uri.parse() I'm passing url to mp4 file.

--edit I forgot to tell, that in LogCat in ICS ang JB, MediaPlayer is not even called (in Froyo and Gingerbread there is some infos generated by MediaPlayer class).

I am getting my video resource from raw folder in res. You can also use direct URL. I have commited it in below code.

Write in XML layout file

VideoView
        android:id="@+id/videoView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"<
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />

and write in java code

video = (VideoView) findViewById(R.id.videoView1);
video.setVideoPath("android.resource://com.example.s3project/raw/" +R.raw.bggreen1);
//video.setVideoURI(Uri.parse("http://www.pocketjourney.com/downloads/pj/video/famous.3gp"));
        video.start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM