From 1024c120360bd843b33ea97d3d7ed2048ce561e7 Mon Sep 17 00:00:00 2001 From: Ricter Z Date: Sat, 17 Nov 2018 22:14:36 +0800 Subject: [PATCH] remove video player --- app/src/main/AndroidManifest.xml | 3 - .../bgmi/app/bgmi_android/PlayerActivity.java | 213 ------------------ .../holders/BangumiViewHolder.java | 1 - app/src/main/res/layout/activity_player.xml | 24 -- 4 files changed, 241 deletions(-) delete mode 100644 app/src/main/java/bgmi/app/bgmi_android/PlayerActivity.java delete mode 100644 app/src/main/res/layout/activity_player.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 979adf2..c11ca13 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,9 +18,6 @@ - \ No newline at end of file diff --git a/app/src/main/java/bgmi/app/bgmi_android/PlayerActivity.java b/app/src/main/java/bgmi/app/bgmi_android/PlayerActivity.java deleted file mode 100644 index 2257ac4..0000000 --- a/app/src/main/java/bgmi/app/bgmi_android/PlayerActivity.java +++ /dev/null @@ -1,213 +0,0 @@ -package bgmi.app.bgmi_android; - -import android.content.Context; -import android.net.Uri; -import android.os.Handler; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import android.widget.ProgressBar; - -import com.google.android.exoplayer2.DefaultLoadControl; -import com.google.android.exoplayer2.ExoPlaybackException; -import com.google.android.exoplayer2.ExoPlayer; -import com.google.android.exoplayer2.ExoPlayerFactory; -import com.google.android.exoplayer2.LoadControl; -import com.google.android.exoplayer2.PlaybackParameters; -import com.google.android.exoplayer2.SimpleExoPlayer; -import com.google.android.exoplayer2.Timeline; -import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; -import com.google.android.exoplayer2.extractor.ExtractorsFactory; -import com.google.android.exoplayer2.source.ExtractorMediaSource; -import com.google.android.exoplayer2.source.MediaSource; -import com.google.android.exoplayer2.source.TrackGroupArray; -import com.google.android.exoplayer2.text.Cue; -import com.google.android.exoplayer2.text.TextRenderer; -import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; -import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; -import com.google.android.exoplayer2.trackselection.TrackSelection; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; -import com.google.android.exoplayer2.trackselection.TrackSelector; -import com.google.android.exoplayer2.ui.SimpleExoPlayerView; -import com.google.android.exoplayer2.upstream.BandwidthMeter; -import com.google.android.exoplayer2.upstream.DataSource; -import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; -import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; -import com.google.android.exoplayer2.util.Util; - -import java.util.Formatter; -import java.util.List; -import java.util.Locale; - -public class PlayerActivity extends AppCompatActivity { - private SimpleExoPlayerView mExoPlayerView; - private SimpleExoPlayer mSimpleExoPlayer; - Uri playerUri; - private ProgressBar mProgressBar; - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); - setContentView(R.layout.activity_player); - mProgressBar = findViewById(R.id.progressBar); - - playerUri = getIntent().getData(); - - initPlayer(); - playVideo(); - } - - private void initPlayer() { - BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); - TrackSelection.Factory videoTackSelectionFactory = - new AdaptiveTrackSelection.Factory(bandwidthMeter); - TrackSelector trackSelector = - new DefaultTrackSelector(videoTackSelectionFactory); - LoadControl loadControl = new DefaultLoadControl(); - mSimpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this,trackSelector,loadControl); - mExoPlayerView = findViewById(R.id.exoView); - mExoPlayerView.setPlayer(mSimpleExoPlayer); - } - - private void playVideo() { - DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); - DataSource.Factory dataSourceFactory - = new DefaultDataSourceFactory(PlayerActivity.this, - Util.getUserAgent(PlayerActivity.this,"useExoplayer"),bandwidthMeter); - ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); - - MediaSource videoSource = new ExtractorMediaSource(playerUri,dataSourceFactory,extractorsFactory, - null,null); - mSimpleExoPlayer.prepare(videoSource); - mSimpleExoPlayer.addListener(eventListener); - mSimpleExoPlayer.setPlayWhenReady(true); - } - - - TextRenderer.Output mOutput = new TextRenderer.Output() { - @Override - public void onCues(List cues) { - } - }; - - private SimpleExoPlayer.VideoListener mVideoListener = new SimpleExoPlayer.VideoListener() { - @Override - public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { - - } - - @Override - public void onRenderedFirstFrame() { - } - }; - - - private ExoPlayer.EventListener eventListener = new ExoPlayer.EventListener() { - @Override - public void onTimelineChanged(Timeline timeline, Object manifest, int reason) { - - } - - @Override - public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { - - } - - @Override - public void onLoadingChanged(boolean isLoading) { - - } - - @Override - public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { - switch (playbackState){ - case ExoPlayer.STATE_ENDED: - //Stop playback and return to start position - setPlayPause(false); - mSimpleExoPlayer.seekTo(0); - break; - case ExoPlayer.STATE_READY: - mProgressBar.setVisibility(View.GONE); - setProgress(0); - break; - case ExoPlayer.STATE_BUFFERING: - mProgressBar.setVisibility(View.VISIBLE); - break; - case ExoPlayer.STATE_IDLE: - break; - } - } - - @Override - public void onRepeatModeChanged(int repeatMode) { - - } - - @Override - public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) { - - } - - @Override - public void onPlayerError(ExoPlaybackException error) { - - } - - @Override - public void onPositionDiscontinuity(int reason) { - - } - - @Override - public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { - - } - - @Override - public void onSeekProcessed() { - - } - - }; - - private void setPlayPause(boolean play){ - mSimpleExoPlayer.setPlayWhenReady(play); - } - - private String stringForTime(int timeMs) { - StringBuilder mFormatBuilder; - Formatter mFormatter; - mFormatBuilder = new StringBuilder(); - mFormatter = new Formatter(mFormatBuilder, Locale.getDefault()); - int totalSeconds = timeMs / 1000; - - int seconds = totalSeconds % 60; - int minutes = (totalSeconds / 60) % 60; - int hours = totalSeconds / 3600; - - mFormatBuilder.setLength(0); - if (hours > 0) { - return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString(); - } else { - return mFormatter.format("%02d:%02d", minutes, seconds).toString(); - } - } - - @Override - protected void onPause() { - super.onPause(); - mSimpleExoPlayer.stop(); - } - - @Override - protected void onStop() { - super.onStop(); - mSimpleExoPlayer.release(); - } -} diff --git a/app/src/main/java/bgmi/app/bgmi_android/holders/BangumiViewHolder.java b/app/src/main/java/bgmi/app/bgmi_android/holders/BangumiViewHolder.java index 391b2e8..21a90cb 100644 --- a/app/src/main/java/bgmi/app/bgmi_android/holders/BangumiViewHolder.java +++ b/app/src/main/java/bgmi/app/bgmi_android/holders/BangumiViewHolder.java @@ -17,7 +17,6 @@ import java.util.Collections; import java.util.List; -import bgmi.app.bgmi_android.PlayerActivity; import bgmi.app.bgmi_android.R; import bgmi.app.bgmi_android.models.Bangumi; import bgmi.app.bgmi_android.utils.BGmiProperties; diff --git a/app/src/main/res/layout/activity_player.xml b/app/src/main/res/layout/activity_player.xml deleted file mode 100644 index 972eac3..0000000 --- a/app/src/main/res/layout/activity_player.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - -