Playing video using MediaPlayer class

前端 未结 4 2338

I am trying to make use of MediaPlayer class for playing a video file. The problem is video is not getting displayed at all though I can hear the sound in the video

相关标签:
4条回答
  • 2021-02-13 02:23

    You can override the onSizeChanged() function of the SurfaceView class to get and set the size of the view.

    protected void onSizeChanged (int w, int h, int oldw, int oldh)
    

    When ever the screen size has changed, this class is called.

    As a second alternative, you may be able to set the size by setting the layout parameters (unsure if this works with ScrollView):

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        android.view.ViewGroup.LayoutParams lp = this.getLayoutParams();
        lp.width = 1000; // required width
        lp.height = 1000; // required height
        this.setLayoutParams(lp);
    }
    
    0 讨论(0)
  • 2021-02-13 02:23

    set surface View height and width to fill parent in xml file.

      <SurfaceView
    android:id="@+id/surfaceView1"
    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" />
    
    0 讨论(0)
  • 2021-02-13 02:23

    Well, I don't know if you need an specific situation, but have you already tried FullscreenVideoView?

    It tries to abstracts all those SurfaceView problems and you can focus only in UI buttons. As It's open, you can subclass FullscreenVideoView and customize as you need.

    0 讨论(0)
  • 2021-02-13 02:24

    Setting your SurfaceView layout to wrap_content will not size a video to play at the proper aspect ratio.

    You can refer to this answer link

    https://stackoverflow.com/a/6283676/1441666

    And also this blog Play media on surfaceview using android.media.MediaPlayer

    0 讨论(0)
提交回复
热议问题