summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-08-05 13:56:03 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-08-05 13:56:03 +0200
commitc07bf6691ddad9bf59431c16da4799ebf44d5c02 (patch)
treee281178c9df8b69b5a196c3810f99accb60e997b /src
parent1972652cb1251f0fd5aad2b8fdac13ce27f84f3b (diff)
downloadAntennaPod-c07bf6691ddad9bf59431c16da4799ebf44d5c02.zip
Videoplayback is now working
Diffstat (limited to 'src')
-rw-r--r--src/de/danoeh/antennapod/activity/AudioplayerActivity.java5
-rw-r--r--src/de/danoeh/antennapod/activity/MainActivity.java3
-rw-r--r--src/de/danoeh/antennapod/activity/MediaplayerActivity.java27
-rw-r--r--src/de/danoeh/antennapod/activity/VideoplayerActivity.java79
-rw-r--r--src/de/danoeh/antennapod/feed/FeedManager.java3
-rw-r--r--src/de/danoeh/antennapod/service/PlaybackService.java50
-rw-r--r--src/de/danoeh/antennapod/service/PlayerWidgetService.java2
7 files changed, 102 insertions, 67 deletions
diff --git a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java
index 5866461a0..58c2991cb 100644
--- a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java
+++ b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java
@@ -1,5 +1,6 @@
package de.danoeh.antennapod.activity;
+import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
@@ -22,7 +23,6 @@ public class AudioplayerActivity extends MediaplayerActivity {
final String TAG = "AudioplayerActivity";
- // Widgets
private CoverFragment coverFragment;
private ItemDescriptionFragment descriptionFragment;
ViewPager viewpager;
@@ -32,8 +32,7 @@ public class AudioplayerActivity extends MediaplayerActivity {
@Override
protected void onAwaitingVideoSurface() {
- // TODO Auto-generated method stub
-
+ startActivity(new Intent(this, VideoplayerActivity.class));
}
@Override
diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java
index a8d436813..98b110ec2 100644
--- a/src/de/danoeh/antennapod/activity/MainActivity.java
+++ b/src/de/danoeh/antennapod/activity/MainActivity.java
@@ -24,6 +24,7 @@ import de.danoeh.antennapod.fragment.FeedlistFragment;
import de.danoeh.antennapod.fragment.QueueFragment;
import de.danoeh.antennapod.fragment.UnreadItemlistFragment;
import de.danoeh.antennapod.service.DownloadService;
+import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.StorageUtils;
import de.danoeh.antennapod.AppConfig;
@@ -104,7 +105,7 @@ public class MainActivity extends SherlockFragmentActivity {
startActivity(new Intent(this, PreferenceActivity.class));
return true;
case R.id.show_player:
- startActivity(new Intent(this, AudioplayerActivity.class));
+ startActivity(PlaybackService.getPlayerActivityIntent(this));
return true;
case R.id.opml_import:
startActivity(new Intent(this, OpmlImportActivity.class));
diff --git a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
index a4e3af76e..3fe987bea 100644
--- a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
+++ b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
@@ -377,9 +377,9 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity {
break;
}
}
-
+
protected abstract void onAwaitingVideoSurface();
-
+
protected abstract void postStatusMsg(int resId);
protected abstract void clearStatusMsg();
@@ -543,30 +543,13 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity {
if (AppConfig.DEBUG)
Log.d(TAG, "Querying service info");
if (playbackService != null) {
- int requestedOrientation;
status = playbackService.getStatus();
media = playbackService.getMedia();
invalidateOptionsMenu();
- if (playbackService.isPlayingVideo()) {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
- } else {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
- }
- // check if orientation is correct
- if ((requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE && orientation == Configuration.ORIENTATION_LANDSCAPE)
- || (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && orientation == Configuration.ORIENTATION_PORTRAIT)) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Orientation correct");
- setupGUI();
- handleStatus();
- } else {
- if (AppConfig.DEBUG)
- Log.d(TAG,
- "Orientation incorrect, waiting for orientation change");
- }
+ setupGUI();
+ handleStatus();
+
} else {
Log.e(TAG,
"queryService() was called without an existing connection to playbackservice");
diff --git a/src/de/danoeh/antennapod/activity/VideoplayerActivity.java b/src/de/danoeh/antennapod/activity/VideoplayerActivity.java
index e80fd6119..c2975e8ec 100644
--- a/src/de/danoeh/antennapod/activity/VideoplayerActivity.java
+++ b/src/de/danoeh/antennapod/activity/VideoplayerActivity.java
@@ -6,10 +6,12 @@ import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.service.PlayerStatus;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
+import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
+import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.VideoView;
@@ -20,16 +22,22 @@ public class VideoplayerActivity extends MediaplayerActivity implements
/** True if video controls are currently visible. */
private boolean videoControlsShowing = true;
+ private boolean videoSurfaceCreated = false;
private VideoControlsHider videoControlsToggler;
private LinearLayout videoOverlay;
private VideoView videoview;
@Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
protected void onPause() {
super.onPause();
if (PlaybackService.isRunning && playbackService != null
- && playbackService.isPlayingVideo()) {
+ && PlaybackService.isPlayingVideo()) {
playbackService.stop();
}
if (videoControlsToggler != null) {
@@ -38,8 +46,6 @@ public class VideoplayerActivity extends MediaplayerActivity implements
finish();
}
-
-
@Override
protected void setupGUI() {
super.setupGUI();
@@ -53,11 +59,14 @@ public class VideoplayerActivity extends MediaplayerActivity implements
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
-
-
@Override
protected void onAwaitingVideoSurface() {
- playbackService.setVideoSurface(videoview.getHolder());
+ if (videoSurfaceCreated) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG,
+ "Videosurface already created, setting videosurface now");
+ playbackService.setVideoSurface(videoview.getHolder());
+ }
}
@Override
@@ -71,7 +80,7 @@ public class VideoplayerActivity extends MediaplayerActivity implements
// TODO Auto-generated method stub
}
-
+
View.OnTouchListener onVideoviewTouched = new View.OnTouchListener() {
@Override
@@ -117,33 +126,6 @@ public class VideoplayerActivity extends MediaplayerActivity implements
videoControlsShowing = !videoControlsShowing;
}
-
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height) {
- holder.setFixedSize(width, height);
- }
-
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Videoview holder created");
- if (status == PlayerStatus.AWAITING_VIDEO_SURFACE) {
- if (playbackService != null) {
- playbackService.setVideoSurface(holder);
- } else {
- Log.e(TAG,
- "Could'nt attach surface to mediaplayer - reference to service was null");
- }
- }
-
- }
-
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- if (AppConfig.DEBUG) Log.d(TAG, "Videosurface was destroyed");
- }
-
/** Hides the videocontrols after a certain period of time. */
public class VideoControlsHider extends AsyncTask<Void, Void, Void> {
@Override
@@ -183,4 +165,33 @@ public class VideoplayerActivity extends MediaplayerActivity implements
}
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width,
+ int height) {
+ holder.setFixedSize(width, height);
+ }
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Videoview holder created");
+ videoSurfaceCreated = true;
+ if (status == PlayerStatus.AWAITING_VIDEO_SURFACE) {
+ if (playbackService != null) {
+ playbackService.setVideoSurface(holder);
+ } else {
+ Log.e(TAG,
+ "Could'nt attach surface to mediaplayer - reference to service was null");
+ }
+ }
+
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Videosurface was destroyed");
+ videoSurfaceCreated = false;
+ }
+
}
diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java
index 5b4e12635..d645cf3b6 100644
--- a/src/de/danoeh/antennapod/feed/FeedManager.java
+++ b/src/de/danoeh/antennapod/feed/FeedManager.java
@@ -106,8 +106,7 @@ public class FeedManager {
context.startService(launchIntent);
if (showPlayer) {
// Launch Mediaplayer
- Intent playerIntent = new Intent(context, AudioplayerActivity.class);
- context.startActivity(playerIntent);
+ context.startActivity(PlaybackService.getPlayerActivityIntent(context, media));
}
}
diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java
index 373af2957..3bbbdba66 100644
--- a/src/de/danoeh/antennapod/service/PlaybackService.java
+++ b/src/de/danoeh/antennapod/service/PlaybackService.java
@@ -28,6 +28,7 @@ import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.AudioplayerActivity;
+import de.danoeh.antennapod.activity.VideoplayerActivity;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedManager;
@@ -47,6 +48,8 @@ public class PlaybackService extends Service {
public static final String PREF_LAST_PLAYED_FEED_ID = "de.danoeh.antennapod.preferences.lastPlayedFeedId";
/** True if last played media was streamed. */
public static final String PREF_LAST_IS_STREAM = "de.danoeh.antennapod.preferences.lastIsStream";
+ /** True if last played media was a video. */
+ public static final String PREF_LAST_IS_VIDEO = "de.danoeh.antennapod.preferences.lastIsVideo";
/** Contains the id of the FeedMedia object. */
public static final String EXTRA_MEDIA_ID = "extra.de.danoeh.antennapod.service.mediaId";
@@ -91,7 +94,6 @@ public class PlaybackService extends Service {
/** True if media should be streamed (Extracted from Intent Extra) . */
private boolean shouldStream;
private boolean startWhenPrepared;
- private boolean playingVideo;
private FeedManager manager;
private PlayerStatus status;
private PositionSaver positionSaver;
@@ -99,6 +101,8 @@ public class PlaybackService extends Service {
private volatile PlayerStatus statusBeforeSeek;
+ private static boolean playingVideo;
+
/** True if mediaplayer was paused because it lost audio focus temporarily */
private boolean pausedBecauseOfTransientAudiofocusLoss;
@@ -110,6 +114,43 @@ public class PlaybackService extends Service {
}
}
+ /**
+ * Returns an intent which starts an audio- or videoplayer, depending on the
+ * type of media that is being played. If the playbackservice is not
+ * running, the type of the last played media will be looked up.
+ * */
+ public static Intent getPlayerActivityIntent(Context context) {
+ if (isRunning) {
+ if (playingVideo) {
+ return new Intent(context, VideoplayerActivity.class);
+ } else {
+ return new Intent(context, AudioplayerActivity.class);
+ }
+ } else {
+ SharedPreferences pref = context.getApplicationContext()
+ .getSharedPreferences(PodcastApp.PREF_NAME, 0);
+ boolean isVideo = pref.getBoolean(PREF_LAST_IS_VIDEO, false);
+ if (isVideo) {
+ return new Intent(context, VideoplayerActivity.class);
+ } else {
+ return new Intent(context, AudioplayerActivity.class);
+ }
+ }
+ }
+
+ /**
+ * Same as getPlayerActivityIntent(context), but here the type of activity
+ * depends on the FeedMedia that is provided as an argument.
+ */
+ public static Intent getPlayerActivityIntent(Context context,
+ FeedMedia media) {
+ if (media.getMime_type().startsWith("video")) {
+ return new Intent(context, VideoplayerActivity.class);
+ } else {
+ return new Intent(context, AudioplayerActivity.class);
+ }
+ }
+
@Override
public void onCreate() {
super.onCreate();
@@ -529,6 +570,7 @@ public class PlaybackService extends Service {
editor.putLong(PREF_LAST_PLAYED_ID, media.getId());
editor.putLong(PREF_LAST_PLAYED_FEED_ID, feed.getId());
editor.putBoolean(PREF_LAST_IS_STREAM, shouldStream);
+ editor.putBoolean(PREF_LAST_IS_VIDEO, playingVideo);
editor.commit();
player.start();
@@ -562,8 +604,8 @@ public class PlaybackService extends Service {
/** Prepares notification and starts the service in the foreground. */
private void setupNotification() {
- PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(
- this, AudioplayerActivity.class),
+ PendingIntent pIntent = PendingIntent.getActivity(this, 0,
+ PlaybackService.getPlayerActivityIntent(this),
PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap icon = BitmapFactory.decodeResource(null,
@@ -809,7 +851,7 @@ public class PlaybackService extends Service {
}
- public boolean isPlayingVideo() {
+ public static boolean isPlayingVideo() {
return playingVideo;
}
diff --git a/src/de/danoeh/antennapod/service/PlayerWidgetService.java b/src/de/danoeh/antennapod/service/PlayerWidgetService.java
index b574ef0d7..424646074 100644
--- a/src/de/danoeh/antennapod/service/PlayerWidgetService.java
+++ b/src/de/danoeh/antennapod/service/PlayerWidgetService.java
@@ -68,7 +68,7 @@ public class PlayerWidgetService extends Service {
RemoteViews views = new RemoteViews(getPackageName(),
R.layout.player_widget);
PendingIntent startMediaplayer = PendingIntent.getActivity(this, 0,
- new Intent(this, AudioplayerActivity.class), 0);
+ PlaybackService.getPlayerActivityIntent(this), 0);
views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
if (playbackService != null) {