Commit 674702dc6fbc244be632504654bfeee1cf6446a7
1 parent
4c9b109a
代码整理
Showing
5 changed files
with
11 additions
and
50 deletions
app/src/main/java/com/cnlive/demo/video/BarrageActivity.java
| @@ -19,10 +19,10 @@ public class BarrageActivity extends Activity implements View.OnClickListener{ | @@ -19,10 +19,10 @@ public class BarrageActivity extends Activity implements View.OnClickListener{ | ||
| 19 | super.onCreate(savedInstanceState); | 19 | super.onCreate(savedInstanceState); |
| 20 | setContentView(R.layout.activity_barrage); | 20 | setContentView(R.layout.activity_barrage); |
| 21 | barrageLayout = (BarrageLayout) findViewById(R.id.barrage); | 21 | barrageLayout = (BarrageLayout) findViewById(R.id.barrage); |
| 22 | - if (barrageLayout != null) barrageLayout.init(BarrageBaseView.class, 400, 10, 10, 4); | 22 | + barrageLayout.init(BarrageBaseView.class, 400, 10, 10, 4); |
| 23 | 23 | ||
| 24 | barrageGiftLayout = (BarrageLayout) findViewById(R.id.barrage_gift); | 24 | barrageGiftLayout = (BarrageLayout) findViewById(R.id.barrage_gift); |
| 25 | - if (barrageGiftLayout != null) barrageGiftLayout.init(BarrageGiftView.class, 400, 4, 10, 6); | 25 | + barrageGiftLayout.init(BarrageGiftView.class, 400, 4, 10, 6); |
| 26 | 26 | ||
| 27 | findViewById(R.id.addMessage).setOnClickListener(this); | 27 | findViewById(R.id.addMessage).setOnClickListener(this); |
| 28 | findViewById(R.id.addGiftMessage).setOnClickListener(this); | 28 | findViewById(R.id.addGiftMessage).setOnClickListener(this); |
app/src/main/java/com/cnlive/demo/video/MainActivity.java
| @@ -11,9 +11,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | @@ -11,9 +11,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | ||
| 11 | protected void onCreate(Bundle savedInstanceState) { | 11 | protected void onCreate(Bundle savedInstanceState) { |
| 12 | super.onCreate(savedInstanceState); | 12 | super.onCreate(savedInstanceState); |
| 13 | setContentView(R.layout.activity_main); | 13 | setContentView(R.layout.activity_main); |
| 14 | - findViewById(R.id.play).setOnClickListener(this); | ||
| 15 | - findViewById(R.id.barrageBtn).setOnClickListener(this); | ||
| 16 | - findViewById(R.id.videoId).setOnClickListener(this); | ||
| 17 | } | 14 | } |
| 18 | 15 | ||
| 19 | @Override | 16 | @Override |
app/src/main/java/com/cnlive/demo/video/MediaPlayerActivity.java
| @@ -16,8 +16,6 @@ import android.view.SurfaceHolder; | @@ -16,8 +16,6 @@ import android.view.SurfaceHolder; | ||
| 16 | import android.view.SurfaceHolder.Callback; | 16 | import android.view.SurfaceHolder.Callback; |
| 17 | import android.view.SurfaceView; | 17 | import android.view.SurfaceView; |
| 18 | import android.view.View; | 18 | import android.view.View; |
| 19 | -import android.view.ViewGroup.LayoutParams; | ||
| 20 | -import android.view.WindowManager; | ||
| 21 | import android.widget.ImageView; | 19 | import android.widget.ImageView; |
| 22 | import android.widget.LinearLayout; | 20 | import android.widget.LinearLayout; |
| 23 | import android.widget.RelativeLayout; | 21 | import android.widget.RelativeLayout; |
| @@ -329,39 +327,6 @@ public class MediaPlayerActivity extends Activity implements View.OnClickListene | @@ -329,39 +327,6 @@ public class MediaPlayerActivity extends Activity implements View.OnClickListene | ||
| 329 | super.onConfigurationChanged(newConfig); | 327 | super.onConfigurationChanged(newConfig); |
| 330 | } | 328 | } |
| 331 | 329 | ||
| 332 | - private void scaleVideoView() { | ||
| 333 | - if (mMediaPlayer == null || mMediaPlayer.getVideoHeight() <= 0 || mVideoSurfaceView == null) | ||
| 334 | - return; | ||
| 335 | - | ||
| 336 | - WindowManager wm = this.getWindowManager(); | ||
| 337 | - int sw = wm.getDefaultDisplay().getWidth(); | ||
| 338 | - int sh = wm.getDefaultDisplay().getHeight(); | ||
| 339 | - int videoWidth = mVideoWidth; | ||
| 340 | - int videoHeight = mVideoHeight; | ||
| 341 | - int visibleWidth = 0; | ||
| 342 | - int visibleHeight = 0; | ||
| 343 | - | ||
| 344 | - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { | ||
| 345 | - visibleWidth = sw > sh ? sh : sw; | ||
| 346 | - visibleHeight = (int) Math.ceil(visibleWidth * videoHeight / videoWidth); | ||
| 347 | - } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { | ||
| 348 | - | ||
| 349 | - if (videoHeight * sw > videoWidth * sh) { | ||
| 350 | - visibleHeight = sh; | ||
| 351 | - visibleWidth = (int) Math.ceil(videoWidth * visibleHeight / videoHeight); | ||
| 352 | - } else { | ||
| 353 | - visibleWidth = sw; | ||
| 354 | - visibleHeight = (int) Math.ceil(visibleWidth * videoHeight / videoWidth); | ||
| 355 | - } | ||
| 356 | - } | ||
| 357 | - | ||
| 358 | - LayoutParams lp = mVideoSurfaceView.getLayoutParams(); | ||
| 359 | - lp.width = visibleWidth; | ||
| 360 | - lp.height = visibleHeight; | ||
| 361 | - mVideoSurfaceView.setLayoutParams(lp); | ||
| 362 | - | ||
| 363 | - mVideoSurfaceView.invalidate(); | ||
| 364 | - } | ||
| 365 | 330 | ||
| 366 | // Maybe we could support gesture detect | 331 | // Maybe we could support gesture detect |
| 367 | private void dealTouchEvent(View view, MotionEvent event) { | 332 | private void dealTouchEvent(View view, MotionEvent event) { |
app/src/main/java/com/cnlive/demo/video/VideoViewActivity.java
| @@ -3,14 +3,10 @@ package com.cnlive.demo.video; | @@ -3,14 +3,10 @@ package com.cnlive.demo.video; | ||
| 3 | import android.app.Activity; | 3 | import android.app.Activity; |
| 4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
| 5 | 5 | ||
| 6 | -import com.cnlive.demo.video.model.ProgramVod; | 6 | +import com.cnlive.demo.video.model.ProgramLive; |
| 7 | import com.cnlive.libs.video.video.VideoView; | 7 | import com.cnlive.libs.video.video.VideoView; |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -/** | ||
| 11 | - * Created by xiansong on 2016/10/8. | ||
| 12 | - */ | ||
| 13 | - | ||
| 14 | public class VideoViewActivity extends Activity { | 10 | public class VideoViewActivity extends Activity { |
| 15 | 11 | ||
| 16 | protected VideoView videoView; | 12 | protected VideoView videoView; |
| @@ -44,10 +40,10 @@ public class VideoViewActivity extends Activity { | @@ -44,10 +40,10 @@ public class VideoViewActivity extends Activity { | ||
| 44 | videoView = (VideoView) findViewById(R.id.videoview); | 40 | videoView = (VideoView) findViewById(R.id.videoview); |
| 45 | 41 | ||
| 46 | //视讯云 直播 | 42 | //视讯云 直播 |
| 47 | -// videoView.setDataSource(new ProgramLive(),false); | 43 | + videoView.setDataSource(new ProgramLive(),false); |
| 48 | 44 | ||
| 49 | //视讯云 点播 | 45 | //视讯云 点播 |
| 50 | - videoView.setDataSourceByAuth(new ProgramVod(), false); | 46 | +// videoView.setDataSourceByAuth(new ProgramVod(), false); |
| 51 | 47 | ||
| 52 | //本地视频 | 48 | //本地视频 |
| 53 | // try { | 49 | // try { |
app/src/main/res/layout/activity_main.xml
| @@ -13,18 +13,21 @@ | @@ -13,18 +13,21 @@ | ||
| 13 | android:id="@+id/play" | 13 | android:id="@+id/play" |
| 14 | android:layout_width="wrap_content" | 14 | android:layout_width="wrap_content" |
| 15 | android:layout_height="wrap_content" | 15 | android:layout_height="wrap_content" |
| 16 | - android:text="视频基本操作" /> | 16 | + android:text="视频基本操作" |
| 17 | + android:onClick="onClick"/> | ||
| 17 | 18 | ||
| 18 | <Button android:id="@+id/videoId" | 19 | <Button android:id="@+id/videoId" |
| 19 | android:layout_width="wrap_content" | 20 | android:layout_width="wrap_content" |
| 20 | android:layout_height="wrap_content" | 21 | android:layout_height="wrap_content" |
| 21 | android:text="播放视讯云视频" | 22 | android:text="播放视讯云视频" |
| 22 | - android:layout_below="@+id/play"/> | 23 | + android:layout_below="@+id/play" |
| 24 | + android:onClick="onClick"/> | ||
| 23 | 25 | ||
| 24 | <Button | 26 | <Button |
| 25 | android:id="@+id/barrageBtn" | 27 | android:id="@+id/barrageBtn" |
| 26 | android:layout_width="wrap_content" | 28 | android:layout_width="wrap_content" |
| 27 | android:layout_height="wrap_content" | 29 | android:layout_height="wrap_content" |
| 28 | android:text="弹幕" | 30 | android:text="弹幕" |
| 29 | - android:layout_below="@+id/videoId"/> | 31 | + android:layout_below="@+id/videoId" |
| 32 | + android:onClick="onClick"/> | ||
| 30 | </RelativeLayout> | 33 | </RelativeLayout> |