QuickHand_PlayerActivity_Player_design_.m3u8視頻播放格式(如快手短視頻

  1. 導入依賴
	//依賴
    implementation 'com.shuyu:GSYVideoPlayer:7.1.6'
    //design配合視頻使用
    implementation 'com.google.android.material:material:1.1.0'
    
	//需設置當前項目build.gradle
	compileSdkVersion 30
	buildToolsVersion "30.0.2"

	minSdkVersion 24
	targetSdkVersion 30

2.清單

 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
 //在application添加兩個常用屬性
 <application
 	  android:requestLegacyExternalStorage="true"
  	  android:usesCleartextTraffic="true"
  	  />

3.activity_player.xml可直接使用

 <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:minHeight="200dp"
                >
                
                <com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
                    android:id="@+id/player_player"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_collapseMode="parallax"
                    >


                </com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer>
                
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:orientation="horizontal"
                    android:background="#35088693"
                    app:layout_collapseMode="pin"
                    >

                <Button
                    android:id="@+id/player_btn_back"
                    android:layout_width="50dp"
                    android:layout_height="wrap_content"
                    android:background="@null"
                    android:text="<"
                    android:textSize="30dp"
                    android:textColor="#ffffff"
                    />

                </LinearLayout>


                
            </com.google.android.material.appbar.CollapsingToolbarLayout>



        </com.google.android.material.appbar.AppBarLayout>


        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="1000dp"
                    android:text="紡紗機回覆薩芬撒空間哈佛撒看很快就薩芬"
                    android:textSize="50dp"
                    android:gravity="center"
                    />

            </LinearLayout>


        </androidx.core.widget.NestedScrollView>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

4.PlayerActivity

	//初始化
	private StandardGSYVideoPlayer _playerPlayer;
    private Button _playerBtnBack;

    private void assignViews() {
   
   
        _playerPlayer = (StandardGSYVideoPlayer) findViewById(R.id.player_player);
        _playerBtnBack = (Button) findViewById(R.id.player_btn_back);
    }

		//實現
		assignViews();
 		_playerPlayer.setLooping(true);
        _playerPlayer.setUp("https://txmov2.a.yximgs.com/upic/2020/11/20/18/BMjAyMDExMjAxODQ2MDRfNzc1MDY1NzVfMzk1MjA4MDgzNTJfMV8z_b_B0a59fa9bf8d09647ac718964c969a83a.mp4",true,"");
        _playerPlayer.startPlayLogic();


		//事故
        //點擊關閉當前頁面
        _playerBtnBack.setOnClickListener(new View.OnClickListener() {
   
   
            @Override
            public void onClick(View v) {
   
   
		//_playerPlayer.
                _playerPlayer.getCurrentPlayer().release();
                finish();
            }
        });
//推薦
//網址https://blog.csdn.net/a550508153/article/details/80192100
//       https://blog.csdn.net/wyh_File/article/details/80630700
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章