summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-01 21:01:51 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-01 21:01:51 +0200
commit36cafbc7889a2a977bfebd24c2d4fa3df51aa032 (patch)
tree40d3dae450926eee965a84bb4e59c3b1becc4ac2 /src/de
parent6bde1e99d112b0fd111e0f3e657cb88f71294391 (diff)
downloadAntennaPod-36cafbc7889a2a977bfebd24c2d4fa3df51aa032.zip
Improved video playback
Diffstat (limited to 'src/de')
-rw-r--r--src/de/podfetcher/activity/MediaplayerActivity.java106
-rw-r--r--src/de/podfetcher/service/PlaybackService.java6
2 files changed, 107 insertions, 5 deletions
diff --git a/src/de/podfetcher/activity/MediaplayerActivity.java b/src/de/podfetcher/activity/MediaplayerActivity.java
index 6353f8ad8..1aefbd0a1 100644
--- a/src/de/podfetcher/activity/MediaplayerActivity.java
+++ b/src/de/podfetcher/activity/MediaplayerActivity.java
@@ -20,12 +20,15 @@ import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
+import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
@@ -35,6 +38,7 @@ import android.widget.ViewSwitcher;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.Window;
import com.viewpagerindicator.TabPageIndicator;
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
// when using FF or
// Rev Buttons
-
+ /** Current screen orientation. */
private int orientation;
+ /** True if video controls are currently visible. */
+ private boolean videoControlsShowing = true;
+
private PlaybackService playbackService;
private MediaPositionObserver positionObserver;
+ private VideoControlsHider videoControlsToggler;
private FeedMedia media;
private PlayerStatus status;
@@ -79,6 +87,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
private ImageButton butPlay;
private ImageButton butRev;
private ImageButton butFF;
+ private LinearLayout videoOverlay;
@Override
protected void onStop() {
@@ -136,14 +145,21 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
super.onPause();
if (playbackService.isRunning && playbackService != null
&& playbackService.isPlayingVideo()) {
- playbackService.pause();
+ playbackService.stop();
+ }
+ if (videoControlsToggler != null) {
+ videoControlsToggler.cancel(true);
}
+ finish();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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;
manager = FeedManager.getInstance();
getWindow().setFormat(PixelFormat.TRANSPARENT);
@@ -364,10 +380,12 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
viewpager.setAdapter(pagerAdapter);
tabs.setViewPager(viewpager);
} else {
- setTheme(R.style.Theme_Sherlock_Light_NoActionBar);
+ videoOverlay = (LinearLayout) findViewById(R.id.overlay);
videoview = (VideoView) findViewById(R.id.videoview);
videoview.getHolder().addCallback(this);
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() {
// TODO implement
}
@@ -409,9 +464,10 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
Log.d(TAG, "Orientation correct");
handleStatus();
} 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");
}
@@ -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;
@Override
diff --git a/src/de/podfetcher/service/PlaybackService.java b/src/de/podfetcher/service/PlaybackService.java
index ccba7277a..3496e0beb 100644
--- a/src/de/podfetcher/service/PlaybackService.java
+++ b/src/de/podfetcher/service/PlaybackService.java
@@ -373,6 +373,12 @@ public class PlaybackService extends Service {
stopForeground(true);
}
}
+
+ /** Pauses playback and destroys service. Recommended for video playback. */
+ public void stop() {
+ pause();
+ stopSelf();
+ }
public void play() {
if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED