Improved video playback
This commit is contained in:
parent
6bde1e99d1
commit
36cafbc788
|
@ -20,12 +20,15 @@ import android.support.v4.app.FragmentPagerAdapter;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -35,6 +38,7 @@ import android.widget.ViewSwitcher;
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
|
import com.actionbarsherlock.view.Window;
|
||||||
import com.viewpagerindicator.TabPageIndicator;
|
import com.viewpagerindicator.TabPageIndicator;
|
||||||
|
|
||||||
import de.podfetcher.PodcastApp;
|
import de.podfetcher.PodcastApp;
|
||||||
|
@ -55,11 +59,15 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
private static final int DEFAULT_SEEK_DELTA = 30000; // Seek-Delta to use
|
private static final int DEFAULT_SEEK_DELTA = 30000; // Seek-Delta to use
|
||||||
// when using FF or
|
// when using FF or
|
||||||
// Rev Buttons
|
// Rev Buttons
|
||||||
|
/** Current screen orientation. */
|
||||||
private int orientation;
|
private int orientation;
|
||||||
|
|
||||||
|
/** True if video controls are currently visible. */
|
||||||
|
private boolean videoControlsShowing = true;
|
||||||
|
|
||||||
private PlaybackService playbackService;
|
private PlaybackService playbackService;
|
||||||
private MediaPositionObserver positionObserver;
|
private MediaPositionObserver positionObserver;
|
||||||
|
private VideoControlsHider videoControlsToggler;
|
||||||
|
|
||||||
private FeedMedia media;
|
private FeedMedia media;
|
||||||
private PlayerStatus status;
|
private PlayerStatus status;
|
||||||
|
@ -79,6 +87,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
private ImageButton butPlay;
|
private ImageButton butPlay;
|
||||||
private ImageButton butRev;
|
private ImageButton butRev;
|
||||||
private ImageButton butFF;
|
private ImageButton butFF;
|
||||||
|
private LinearLayout videoOverlay;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
|
@ -136,14 +145,21 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (playbackService.isRunning && playbackService != null
|
if (playbackService.isRunning && playbackService != null
|
||||||
&& playbackService.isPlayingVideo()) {
|
&& playbackService.isPlayingVideo()) {
|
||||||
playbackService.pause();
|
playbackService.stop();
|
||||||
}
|
}
|
||||||
|
if (videoControlsToggler != null) {
|
||||||
|
videoControlsToggler.cancel(true);
|
||||||
|
}
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.d(TAG, "Creating Activity");
|
Log.d(TAG, "Creating Activity");
|
||||||
|
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
|
||||||
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
orientation = getResources().getConfiguration().orientation;
|
orientation = getResources().getConfiguration().orientation;
|
||||||
manager = FeedManager.getInstance();
|
manager = FeedManager.getInstance();
|
||||||
getWindow().setFormat(PixelFormat.TRANSPARENT);
|
getWindow().setFormat(PixelFormat.TRANSPARENT);
|
||||||
|
@ -364,10 +380,12 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
viewpager.setAdapter(pagerAdapter);
|
viewpager.setAdapter(pagerAdapter);
|
||||||
tabs.setViewPager(viewpager);
|
tabs.setViewPager(viewpager);
|
||||||
} else {
|
} else {
|
||||||
setTheme(R.style.Theme_Sherlock_Light_NoActionBar);
|
videoOverlay = (LinearLayout) findViewById(R.id.overlay);
|
||||||
videoview = (VideoView) findViewById(R.id.videoview);
|
videoview = (VideoView) findViewById(R.id.videoview);
|
||||||
videoview.getHolder().addCallback(this);
|
videoview.getHolder().addCallback(this);
|
||||||
videoview.setOnClickListener(playbuttonListener);
|
videoview.setOnClickListener(playbuttonListener);
|
||||||
|
videoview.setOnTouchListener(onVideoviewTouched);
|
||||||
|
setupVideoControlsToggler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,6 +401,43 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private View.OnTouchListener onVideoviewTouched = new View.OnTouchListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
if (videoControlsToggler != null) {
|
||||||
|
videoControlsToggler.cancel(true);
|
||||||
|
}
|
||||||
|
toggleVideoControlsVisibility();
|
||||||
|
setupVideoControlsToggler();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void setupVideoControlsToggler() {
|
||||||
|
if (videoControlsToggler != null) {
|
||||||
|
videoControlsToggler.cancel(true);
|
||||||
|
}
|
||||||
|
videoControlsToggler = new VideoControlsHider();
|
||||||
|
videoControlsToggler.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleVideoControlsVisibility() {
|
||||||
|
if (videoControlsShowing) {
|
||||||
|
getSupportActionBar().hide();
|
||||||
|
videoOverlay.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
getSupportActionBar().show();
|
||||||
|
videoOverlay.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
videoControlsShowing = !videoControlsShowing;
|
||||||
|
}
|
||||||
|
|
||||||
private void handleError() {
|
private void handleError() {
|
||||||
// TODO implement
|
// TODO implement
|
||||||
}
|
}
|
||||||
|
@ -409,7 +464,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
Log.d(TAG, "Orientation correct");
|
Log.d(TAG, "Orientation correct");
|
||||||
handleStatus();
|
handleStatus();
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Orientation incorrect, waiting for orientation change");
|
Log.d(TAG,
|
||||||
|
"Orientation incorrect, waiting for orientation change");
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Connection to Service established");
|
Log.d(TAG, "Connection to Service established");
|
||||||
|
@ -464,6 +520,46 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Hides the videocontrols after a certain period of time. */
|
||||||
|
public class VideoControlsHider extends AsyncTask<Void, Void, Void> {
|
||||||
|
@Override
|
||||||
|
protected void onCancelled() {
|
||||||
|
videoControlsToggler = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
videoControlsToggler = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int WAITING_INTERVALL = 3000;
|
||||||
|
private static final String TAG = "VideoControlsToggler";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Void... values) {
|
||||||
|
if (videoControlsShowing) {
|
||||||
|
Log.d(TAG, "Hiding video controls");
|
||||||
|
getSupportActionBar().hide();
|
||||||
|
videoOverlay.setVisibility(View.GONE);
|
||||||
|
videoControlsShowing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
while (!isCancelled()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(WAITING_INTERVALL);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
publishProgress();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private boolean holderCreated;
|
private boolean holderCreated;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -374,6 +374,12 @@ public class PlaybackService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Pauses playback and destroys service. Recommended for video playback. */
|
||||||
|
public void stop() {
|
||||||
|
pause();
|
||||||
|
stopSelf();
|
||||||
|
}
|
||||||
|
|
||||||
public void play() {
|
public void play() {
|
||||||
if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED
|
if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED
|
||||||
|| status == PlayerStatus.STOPPED) {
|
|| status == PlayerStatus.STOPPED) {
|
||||||
|
|
Loading…
Reference in New Issue