1

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

przebar
  • 531
  • 1
  • 5
  • 19
  • [SOLVED] - the problem was proper LayoutParameters. In API<11 WRAP_CONTENT was working fine. In ICS and newer i had to set manually VideoView's height. So trivial, and so annoying... – przebar Sep 12 '12 at 10:47
  • Could you please put the lines of code where you have set layout params for videoview. – hemanth kumar Apr 04 '14 at 06:57

1 Answers1

0

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();
ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
CoolDeep
  • 41
  • 7
  • yeah, just in case you didn't noticed - i'm doing basicly the same, just in runtime, not in xml. – przebar Sep 12 '12 at 08:41