playback video full screen

前端 未结 5 1901
无人及你
无人及你 2020-11-27 16:51

I am trying to play a video in my app. It has to be embedded.

I went through the \"Play Video Files in Android\" thread.

I am able to play my video using Vi

相关标签:
5条回答
  • 2020-11-27 17:07

    Modified @Javanator's answer a bit, this won't stretch the video:

    <?xml version="1.0" encoding="utf-8"?>
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent" >
       <VideoView android:id="@+id/myvideoview"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_centerVertical="true"
                  android:layout_centerHorizontal="true">
        </VideoView>
     </RelativeLayout>
    

    Hope this helps someone :)

    0 讨论(0)
  • 2020-11-27 17:13

    I know this thread is a few weeks old, but you don't have to copy the video file to the SD card just to play it. Use the following but insert your package name instead of "com.yourcompany.yourproject":

    videoView.setVideoURI(Uri.parse("android.resource://com.yourcompay.yourproject/" + R.raw.yourvideoresource));

    0 讨论(0)
  • 2020-11-27 17:14

    I have solved the problem:

    1. To remove the continue/pause buttons remove the media controller. For the looping issue put OnCompletionListener so that when the video reaches the end, it starts again:

    videoView.setOnCompletionListener(
            new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                videoView.start();
            }
            });
    

    2. To resize the video, override method onMeasure() in VideoView like this:

    public class MyVideoView extends VideoView {
    
            public MyVideoView(Context context) {
                super(context);
            }
    
            @Override
            protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
            {
                 setMeasuredDimension(480,800);
            }
    
        }
    
    0 讨论(0)
  • 2020-11-27 17:25

    No need to do any coding for playing video to full screen mode

    Apply the following layout format over the xml containing the videoview it will for sure will play the video in full screen mode. as it is running mine. :) Hope it helps

     <?xml version="1.0" encoding="utf-8"?>
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent" >
       <VideoView android:id="@+id/myvideoview"
                 android:layout_width="fill_parent"
                 android:layout_alignParentRight="true"
                 android:layout_alignParentLeft="true"
                 android:layout_alignParentTop="true"
                 android:layout_alignParentBottom="true"
                 android:layout_height="fill_parent">
        </VideoView>
     </RelativeLayout>
    

    Plus adding the mediacontroller will also give you the controller to use.

    0 讨论(0)
  • 2020-11-27 17:26

    If you want to play video in full screen, then just add these line of code in your Androidmanifest.xml file, in the activity where this video is going to play. Just add these two lines in android manifest file.

     android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
     android:configChanges="orientation|screenSize"
    

    Like in my androidmanifest.xml file i have added it

      <activity
            android:name="com.appliconic.straminglivevideo.MainActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
    0 讨论(0)
提交回复
热议问题