Videoplayback is now working
This commit is contained in:
parent
1972652cb1
commit
c07bf6691d
@ -69,9 +69,9 @@
|
||||
android:label="@string/downloads_label" />
|
||||
<activity
|
||||
android:name=".activity.AudioplayerActivity"
|
||||
android:configChanges="orientation"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@style/Theme.MediaPlayer" />
|
||||
android:theme="@style/Theme.MediaPlayer" android:screenOrientation="portrait"/>
|
||||
|
||||
<service
|
||||
android:name="de.danoeh.antennapod.service.DownloadService"
|
||||
@ -197,6 +197,7 @@
|
||||
</activity>
|
||||
<activity android:name=".activity.MiroGuideCategoryActivity" android:configChanges="keyboardHidden|orientation" android:theme="@style/StyledIndicators"></activity>
|
||||
<activity android:name=".activity.MiroGuideChannelViewActivity" android:configChanges="keyboard|orientation" android:label="@string/miro_guide_label"></activity>
|
||||
<activity android:name=".activity.VideoplayerActivity" android:configChanges="keyboardHidden|orientation" android:screenOrientation="landscape" android:theme="@style/VideoplayerTheme"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -10,4 +10,9 @@
|
||||
<item name="android:textColor">@color/black</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="VideoplayerTheme" parent="@style/Theme.Sherlock.Light.ForceOverflow">
|
||||
<item name="android:windowActionBarOverlay">true</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -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
|
||||
|
@ -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));
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user