編輯:關於Android編程
package siso.supervideoplayer; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.WindowManager; import siso.videoplayerlib.util.DensityUtil; import siso.videoplayerlib.view.MediaController; import siso.videoplayerlib.view.SuperVideoPlayer; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private SuperVideoPlayer mSuperVideoPlayer; private View mPlayBtnView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSuperVideoPlayer = (SuperVideoPlayer) findViewById(R.id.video_player_item_1); mPlayBtnView = findViewById(R.id.play_btn); mPlayBtnView.setOnClickListener(this); mSuperVideoPlayer.setVideoPlayCallback(mVideoPlayCallback); } /** * 播放器的回調函數 */ private SuperVideoPlayer.VideoPlayCallbackImpl mVideoPlayCallback = new SuperVideoPlayer.VideoPlayCallbackImpl() { /** * 播放器關閉按鈕回調 */ @Override public void onCloseVideo() { mSuperVideoPlayer.close();//關閉VideoView mPlayBtnView.setVisibility(View.VISIBLE); mSuperVideoPlayer.setVisibility(View.GONE); resetPageToPortrait(); } /** * 播放器橫豎屏切換回調 */ @Override public void onSwitchPageType() { if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mSuperVideoPlayer.setPageType(MediaController.PageType.SHRINK); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); mSuperVideoPlayer.setPageType(MediaController.PageType.EXPAND); } } /** * 播放完成回調 */ @Override public void onPlayFinish() { } }; @Override public void onClick(View view) { mPlayBtnView.setVisibility(View.GONE); mSuperVideoPlayer.setVisibility(View.VISIBLE); mSuperVideoPlayer.setAutoHideController(false); Uri uri = Uri.parse("http://v.cctv.com/flash/mp4video6/TMS/2011/01/05/cf752b1c12ce452b3040cab2f90bc265_h264818000nero_aac32-1.mp4"); mSuperVideoPlayer.loadAndPlay(uri,0); } /*** * 旋轉屏幕之後回調 * * @param newConfig newConfig */ @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (null == mSuperVideoPlayer) return; /*** * 根據屏幕方向重新設置播放器的大小 */ if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().getDecorView().invalidate(); float height = DensityUtil.getWidthInPx(this); float width = DensityUtil.getHeightInPx(this); mSuperVideoPlayer.getLayoutParams().height = (int) width; mSuperVideoPlayer.getLayoutParams().width = (int) height; } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { final WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); float width = DensityUtil.getWidthInPx(this); float height = DensityUtil.dip2px(this, 200.f); mSuperVideoPlayer.getLayoutParams().height = (int) height; mSuperVideoPlayer.getLayoutParams().width = (int) width; } } /*** * 恢復屏幕至豎屏 */ private void resetPageToPortrait() { if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mSuperVideoPlayer.setPageType(MediaController.PageType.SHRINK); } } }
<framelayout android:background="@android:color/holo_blue_light" android:layout_height="wrap_content" android:layout_width="match_parent" android:minheight="200dp"> </framelayout>
本文實例介紹了Android中LinearLayout、AbsoluteLayout的用法,希望能對於初學Android的朋友起到一點幫助作用。具體內容如下:Androi
一、前言2分鐘只是一個虛數哈,不過只要你速度快,兩分鐘還真是能搞定的哦。在2.1.8版本以前,極光的配置還是非常麻煩的,需要在清單文件(AndroidManifest.x
Android L: Google已經確認Android L就是Android Lollipop(5.0)。 前幾
Fragment碎片(Fragment)是一種可以嵌入在活動當中的UI片段,它能讓程序更加合理和充分地利用大屏幕的空間,因而在平板上應用的非常廣泛。碎片是什麼這是《第一行
錯誤日志:Error:java.lang.RuntimeExceptio