Pradnnya Bhat Pradnnya Bhat - 5 months ago 65
Android Question

setOnCompletionListener (MediaPlayer.OnCompletionListener) in the type MediaPlayer is not applicable for the arguments

I wanted to detect whether the audio has finished playing, if not then disable one button,
below is the code that I tried

mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
//code to disable button here
}

});


If I add this, I get the below errors

1)Description Resource Path Location Type
OnCompletionListener cannot be resolved to a type LazyAdapter.java /ChattingDoc/src/com/chattingdoc line 278 Java Problem
2)Description Resource Path Location Type
The method setOnCompletionListener(MediaPlayer.OnCompletionListener) in the type MediaPlayer is not applicable for the arguments (new OnCompletionListener(){}) LazyAdapter.java /ChattingDoc/src/com/chattingdoc line 278 Java Problem

Answer
        public class CustomVideoView extends VideoView
        {
        public static int _overrideWidth = 250;
        public static int _overrideHeight = 250;
    public CustomVideoView(Context context) {
    super(context);
   }
    public CustomVideoView(Context context, AttributeSet set) {
    super(context, set);
   }
    public void resizeVideo(int width, int height) {
    _overrideHeight = height;
    _overrideWidth = width;
    // not sure whether it is useful or not but safe to do so
    getHolder().setFixedSize(width, height);
    //getHolder().setSizeFromLayout();
    requestLayout();
    invalidate(); // very important, so that onMeasure will be triggered
  }
     @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
   {
    setMeasuredDimension(_overrideWidth, _overrideHeight);
   }

  }

     //xml file
       <com.destress.CustomVideoView
        android:id="@+id/videoView1"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:gravity="center" />


    //  use this code
     CustomVideoView video;
video = (CustomVideoView) findViewById(R.id.videoView1);

        video.setOnCompletionListener(new OnCompletionListener() 
        {

            @Override
            public void onCompletion(MediaPlayer mp)
            {
                                 //your code 
                            }
                    }
Comments