菜鳥新聞1--自訂VideoView實現歡迎頁面,1--videoview

來源:互聯網
上載者:User

菜鳥新聞1--自訂VideoView實現歡迎頁面,1--videoview

1.自訂VideoView 實現全屏播放

public class CustomVideoView extends VideoView {    public CustomVideoView(Context context) {        super(context);    }    public CustomVideoView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public CustomVideoView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        //重點。        int width = getDefaultSize(0, widthMeasureSpec);        int height = getDefaultSize(0, heightMeasureSpec);        setMeasuredDimension(width, height);    }    @Override    public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) {        super.setOnPreparedListener(l);    }    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {        return super.onKeyDown(keyCode, event);    }}

2.welcome_layout

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    >    <com.cniao5.app36kr_cnk.widget.CustomVideoView        android:id="@+id/welcome_videoview"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:clickable="false"        android:focusable="false"        android:focusableInTouchMode="false"        />     <Button         android:id="@+id/welcome_button"         android:layout_marginBottom="30dp"         android:layout_centerHorizontal="true"         android:layout_alignParentBottom="true"         android:text="進入菜鳥新聞1.0"         android:textSize="16sp"         android:textColor="@color/color_white"         android:layout_width="150dp"         android:layout_height="40dp"         android:background="@drawable/head_bt_bg"/></RelativeLayout>

3.WelcomeActivity

welcome_videoview = (CustomVideoView) this.findViewById(R.id.welcome_videoview);welcome_videoview.setVideoURI(Uri.parse("android.resource://"+this.getPackageName()+"/"+R.raw.kr36));welcome_videoview.start();welcome_videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {    @Override    public void onCompletion(MediaPlayer mp) {        welcome_videoview.start();    }});

  

運行:

運行:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.