0

hi I'm working in my android app which plays videos and now I want to control my video to play in full screen I have a code but it contains errors it says that void is not valid type for variable onmeasure I dont know how to correct that

public class video extends Activity {


String SrcPath =  "rtsp://v8.cache3.c.youtube.com/CjYLENy73wIaLQltaP8vg4qMsBMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYOL6qv2DoMPrUAw=/0/0/0/video.3gp";

/** Called when the activity is first created. */

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video1);


protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec){
   int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
   int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
   this.setMeasuredDimension(parentWidth/2, parentHeight);
   this.setLayoutParams(new *ParentLayoutType*.LayoutParams(parentWidth/2,parentHeight));
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}


VideoView myVideoView = (VideoView)findViewById(R.id.vview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();

}
 }

thanks

2 Answers2

0

The compilation problem is that there are bracket issues. Move

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec){
   int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
   int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
   this.setMeasuredDimension(parentWidth/2, parentHeight);
   this.setLayoutParams(new *ParentLayoutType*.LayoutParams(parentWidth/2,parentHeight));
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

So it is not in onCreate(). Right now, methods can't directly enclose other methods.

Also, onMeasure() is not a method in Activity, but instead in View. You should review the documentation so you figure out exactly what you want to do.

A--C
  • 36,351
  • 10
  • 106
  • 92
  • ok I have taken it off the oncreate and placed it after that oncreate but still getting error for new at this.setlayoutparams....I guess I should replace it with my layout.....and that's what I did but it can't be resolved as variable, – user1794499 Mar 09 '13 at 03:50
  • @user1794499 Keep in mind that `onMeasure()` is a View method. You're working in an `Activity`. As for the setting of the layout params, since this method was for a View class, it uses `this`. What you want instead is to reference your view, which I think you want is your VideoView. Just make the reference an instance variable, that's all. – A--C Mar 09 '13 at 04:06
  • okay got it but what type my variable should be, int? sorry for bothering buddy – user1794499 Mar 09 '13 at 04:08
  • @user1794499 If you're trying to reference a `VideoView`, your type would be `VideoView`. What variable are you talking about? – A--C Mar 09 '13 at 04:11
  • I mean if I'll do as you said...using an instance variable to refference my layout let's say we call that variable new as it's already there in .setlayoutparams....I guess I should give it layout as it's type not videoview coz I need to reference the layout not only the within view – user1794499 Mar 09 '13 at 04:18
  • @user1794499 The `new` keyword is reserved, it can't be a variable. Secondly, you should be working with the View you want to modify. See [this](http://stackoverflow.com/questions/5191099/how-to-set-relativelayout-layout-params-in-code-not-in-xml) question about how to use `setLayoutParams()`. And just a tip: learn Java first before Android. – A--C Mar 09 '13 at 04:20
  • anyway I found someway to do it "at least partially what I need" by including videoview in a relativelayout and set all alignments attributes of that view to true and give fill parent for width and height thanks alot guys and thanks @A--C for the tip – user1794499 Mar 09 '13 at 11:02
0

It seems like you might want to have these two functions as methods in your class:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video1);

    // Set up the video when you create the activity
    VideoView myVideoView = (VideoView)findViewById(R.id.vview);
    myVideoView.setVideoURI(Uri.parse(SrcPath));
    myVideoView.setMediaController(new MediaController(this));
    myVideoView.requestFocus();
}

// On measure should be a different method also in the class video
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
   int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
   int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
   this.setMeasuredDimension(parentWidth/2, parentHeight);
   this.setLayoutParams(new *ParentLayoutType*.LayoutParams(parentWidth/2,parentHeight));
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
silleknarf
  • 1,219
  • 6
  • 22
  • can u just confirm me with new parameter at .setlayoutparams.. should it be my xml file name? – user1794499 Mar 09 '13 at 04:00
  • I'm not sure but you could find out by looking in the xml. The top level view in video1.xml will most likely be called a ____Layout. For example: it might be LinearLayout in which case I think it would make the parameter `new LinearLayout.LayoutParams(parentWidth/2,parentHeight)` – silleknarf Mar 12 '13 at 20:42