mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-12-01 12:31:45 +00:00
Created superclass for mediaplayer, implemented Audioplayer
This commit is contained in:
@ -68,7 +68,7 @@
|
|||||||
android:name="de.danoeh.antennapod.activity.DownloadActivity"
|
android:name="de.danoeh.antennapod.activity.DownloadActivity"
|
||||||
android:label="@string/downloads_label" />
|
android:label="@string/downloads_label" />
|
||||||
<activity
|
<activity
|
||||||
android:name="de.danoeh.antennapod.activity.MediaplayerActivity"
|
android:name=".activity.AudioplayerActivity"
|
||||||
android:configChanges="orientation"
|
android:configChanges="orientation"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:theme="@style/Theme.MediaPlayer" />
|
android:theme="@style/Theme.MediaPlayer" />
|
||||||
|
|||||||
325
src/de/danoeh/antennapod/activity/AudioplayerActivity.java
Normal file
325
src/de/danoeh/antennapod/activity/AudioplayerActivity.java
Normal file
@ -0,0 +1,325 @@
|
|||||||
|
package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.AlertDialog.Builder;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
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.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.VideoView;
|
||||||
|
|
||||||
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
|
import com.viewpagerindicator.TabPageIndicator;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.AppConfig;
|
||||||
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.adapter.SCListAdapter;
|
||||||
|
import de.danoeh.antennapod.feed.SimpleChapter;
|
||||||
|
import de.danoeh.antennapod.fragment.CoverFragment;
|
||||||
|
import de.danoeh.antennapod.fragment.ItemDescriptionFragment;
|
||||||
|
import de.danoeh.antennapod.service.PlaybackService;
|
||||||
|
import de.danoeh.antennapod.service.PlayerStatus;
|
||||||
|
|
||||||
|
public class AudioplayerActivity extends MediaplayerActivity implements
|
||||||
|
SurfaceHolder.Callback {
|
||||||
|
|
||||||
|
final String TAG = "AudioplayerActivity";
|
||||||
|
|
||||||
|
/** True if video controls are currently visible. */
|
||||||
|
private boolean videoControlsShowing = true;
|
||||||
|
private VideoControlsHider videoControlsToggler;
|
||||||
|
|
||||||
|
// Widgets
|
||||||
|
private CoverFragment coverFragment;
|
||||||
|
private ItemDescriptionFragment descriptionFragment;
|
||||||
|
ViewPager viewpager;
|
||||||
|
TabPageIndicator tabs;
|
||||||
|
MediaPlayerPagerAdapter pagerAdapter;
|
||||||
|
VideoView videoview;
|
||||||
|
TextView txtvStatus;
|
||||||
|
LinearLayout videoOverlay;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
if (PlaybackService.isRunning && playbackService != null
|
||||||
|
&& playbackService.isPlayingVideo()) {
|
||||||
|
playbackService.stop();
|
||||||
|
}
|
||||||
|
if (videoControlsToggler != null) {
|
||||||
|
videoControlsToggler.cancel(true);
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAwaitingVideoSurface() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void postStatusMsg(int resId) {
|
||||||
|
txtvStatus.setText(resId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void clearStatusMsg() {
|
||||||
|
txtvStatus.setText("");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setupGUI() {
|
||||||
|
super.setupGUI();
|
||||||
|
txtvStatus = (TextView) findViewById(R.id.txtvStatus);
|
||||||
|
viewpager = (ViewPager) findViewById(R.id.viewpager);
|
||||||
|
tabs = (TabPageIndicator) findViewById(R.id.tabs);
|
||||||
|
|
||||||
|
int tabcount = 2;
|
||||||
|
if (media != null && media.getItem().getSimpleChapters() != null) {
|
||||||
|
tabcount = 3;
|
||||||
|
}
|
||||||
|
pagerAdapter = new MediaPlayerPagerAdapter(getSupportFragmentManager(),
|
||||||
|
tabcount, this);
|
||||||
|
viewpager.setAdapter(pagerAdapter);
|
||||||
|
tabs.setViewPager(viewpager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPositionObserverUpdate() {
|
||||||
|
super.onPositionObserverUpdate();
|
||||||
|
pagerAdapter.notifyMediaPositionChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadMediaInfo() {
|
||||||
|
super.loadMediaInfo();
|
||||||
|
if (!mediaInfoLoaded && media != null) {
|
||||||
|
pagerAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
if (videoControlsShowing) {
|
||||||
|
setupVideoControlsToggler();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
void setupVideoControlsToggler() {
|
||||||
|
if (videoControlsToggler != null) {
|
||||||
|
videoControlsToggler.cancel(true);
|
||||||
|
}
|
||||||
|
videoControlsToggler = new VideoControlsHider();
|
||||||
|
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||||
|
videoControlsToggler
|
||||||
|
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
} else {
|
||||||
|
videoControlsToggler.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleVideoControlsVisibility() {
|
||||||
|
if (videoControlsShowing) {
|
||||||
|
getSupportActionBar().hide();
|
||||||
|
videoOverlay.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
getSupportActionBar().show();
|
||||||
|
videoOverlay.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
videoControlsShowing = !videoControlsShowing;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean holderCreated;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void surfaceChanged(SurfaceHolder holder, int format, int width,
|
||||||
|
int height) {
|
||||||
|
holder.setFixedSize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
|
holderCreated = true;
|
||||||
|
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) {
|
||||||
|
holderCreated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MediaPlayerPagerAdapter extends
|
||||||
|
FragmentStatePagerAdapter {
|
||||||
|
private int numItems;
|
||||||
|
private AudioplayerActivity activity;
|
||||||
|
|
||||||
|
private SherlockListFragment sCChapterFragment;
|
||||||
|
|
||||||
|
private static final int POS_COVER = 0;
|
||||||
|
private static final int POS_DESCR = 1;
|
||||||
|
private static final int POS_CHAPTERS = 2;
|
||||||
|
|
||||||
|
public MediaPlayerPagerAdapter(FragmentManager fm, int numItems,
|
||||||
|
AudioplayerActivity activity) {
|
||||||
|
super(fm);
|
||||||
|
this.numItems = numItems;
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(int position) {
|
||||||
|
if (activity.media != null) {
|
||||||
|
switch (position) {
|
||||||
|
case POS_COVER:
|
||||||
|
activity.coverFragment = CoverFragment
|
||||||
|
.newInstance(activity.media.getItem());
|
||||||
|
return activity.coverFragment;
|
||||||
|
case POS_DESCR:
|
||||||
|
activity.descriptionFragment = ItemDescriptionFragment
|
||||||
|
.newInstance(activity.media.getItem());
|
||||||
|
return activity.descriptionFragment;
|
||||||
|
case POS_CHAPTERS:
|
||||||
|
sCChapterFragment = new SherlockListFragment() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onListItemClick(ListView l, View v,
|
||||||
|
int position, long id) {
|
||||||
|
super.onListItemClick(l, v, position, id);
|
||||||
|
SimpleChapter chapter = (SimpleChapter) this
|
||||||
|
.getListAdapter().getItem(position);
|
||||||
|
if (activity.playbackService != null) {
|
||||||
|
activity.playbackService.seekToChapter(chapter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
sCChapterFragment.setListAdapter(new SCListAdapter(
|
||||||
|
activity, 0, activity.media.getItem()
|
||||||
|
.getSimpleChapters()));
|
||||||
|
|
||||||
|
return sCChapterFragment;
|
||||||
|
default:
|
||||||
|
return CoverFragment.newInstance(null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return CoverFragment.newInstance(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getPageTitle(int position) {
|
||||||
|
switch (position) {
|
||||||
|
case POS_COVER:
|
||||||
|
return activity.getString(R.string.cover_label);
|
||||||
|
case POS_DESCR:
|
||||||
|
return activity.getString(R.string.shownotes_label);
|
||||||
|
case POS_CHAPTERS:
|
||||||
|
return activity.getString(R.string.chapters_label);
|
||||||
|
default:
|
||||||
|
return super.getPageTitle(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return numItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemPosition(Object object) {
|
||||||
|
return POSITION_UNCHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyMediaPositionChanged() {
|
||||||
|
if (sCChapterFragment != null) {
|
||||||
|
ArrayAdapter<SimpleChapter> adapter = (ArrayAdapter<SimpleChapter>) sCChapterFragment
|
||||||
|
.getListAdapter();
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------- ASYNC TASKS
|
||||||
|
|
||||||
|
/** 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 = 5000;
|
||||||
|
private static final String TAG = "VideoControlsToggler";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Void... values) {
|
||||||
|
if (videoControlsShowing) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Hiding video controls");
|
||||||
|
getSupportActionBar().hide();
|
||||||
|
videoOverlay.setVisibility(View.GONE);
|
||||||
|
videoControlsShowing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(WAITING_INTERVALL);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
publishProgress();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -104,7 +104,7 @@ public class MainActivity extends SherlockFragmentActivity {
|
|||||||
startActivity(new Intent(this, PreferenceActivity.class));
|
startActivity(new Intent(this, PreferenceActivity.class));
|
||||||
return true;
|
return true;
|
||||||
case R.id.show_player:
|
case R.id.show_player:
|
||||||
startActivity(new Intent(this, MediaplayerActivity.class));
|
startActivity(new Intent(this, AudioplayerActivity.class));
|
||||||
return true;
|
return true;
|
||||||
case R.id.opml_import:
|
case R.id.opml_import:
|
||||||
startActivity(new Intent(this, OpmlImportActivity.class));
|
startActivity(new Intent(this, OpmlImportActivity.class));
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package de.danoeh.antennapod.activity;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -18,29 +17,19 @@ import android.media.MediaPlayer;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.app.FragmentManager;
|
|
||||||
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.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
|
||||||
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;
|
||||||
import android.widget.VideoView;
|
import android.widget.VideoView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
@ -49,13 +38,11 @@ import com.viewpagerindicator.TabPageIndicator;
|
|||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.PodcastApp;
|
import de.danoeh.antennapod.PodcastApp;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.adapter.SCListAdapter;
|
import de.danoeh.antennapod.activity.AudioplayerActivity.MediaPlayerPagerAdapter;
|
||||||
|
import de.danoeh.antennapod.activity.AudioplayerActivity.MediaPositionObserver;
|
||||||
import de.danoeh.antennapod.dialog.TimeDialog;
|
import de.danoeh.antennapod.dialog.TimeDialog;
|
||||||
import de.danoeh.antennapod.feed.FeedManager;
|
import de.danoeh.antennapod.feed.FeedManager;
|
||||||
import de.danoeh.antennapod.feed.FeedMedia;
|
import de.danoeh.antennapod.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.feed.SimpleChapter;
|
|
||||||
import de.danoeh.antennapod.fragment.CoverFragment;
|
|
||||||
import de.danoeh.antennapod.fragment.ItemDescriptionFragment;
|
|
||||||
import de.danoeh.antennapod.service.PlaybackService;
|
import de.danoeh.antennapod.service.PlaybackService;
|
||||||
import de.danoeh.antennapod.service.PlayerStatus;
|
import de.danoeh.antennapod.service.PlayerStatus;
|
||||||
import de.danoeh.antennapod.util.Converter;
|
import de.danoeh.antennapod.util.Converter;
|
||||||
@ -63,45 +50,129 @@ import de.danoeh.antennapod.util.MediaPlayerError;
|
|||||||
import de.danoeh.antennapod.util.StorageUtils;
|
import de.danoeh.antennapod.util.StorageUtils;
|
||||||
import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler;
|
import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler;
|
||||||
|
|
||||||
public class MediaplayerActivity extends SherlockFragmentActivity implements
|
public abstract class MediaplayerActivity extends SherlockFragmentActivity {
|
||||||
SurfaceHolder.Callback {
|
private static final String TAG = "MediaplayerActivity";
|
||||||
|
|
||||||
private final String TAG = "MediaplayerActivity";
|
static final int DEFAULT_SEEK_DELTA = 30000;
|
||||||
|
|
||||||
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;
|
|
||||||
/** True if media information was loaded. */
|
/** True if media information was loaded. */
|
||||||
private boolean mediaInfoLoaded = false;
|
protected boolean mediaInfoLoaded = false;
|
||||||
|
protected PlaybackService playbackService;
|
||||||
|
protected MediaPositionObserver positionObserver;
|
||||||
|
protected FeedMedia media;
|
||||||
|
protected PlayerStatus status;
|
||||||
|
protected FeedManager manager;
|
||||||
|
|
||||||
private PlaybackService playbackService;
|
protected TextView txtvPosition;
|
||||||
private MediaPositionObserver positionObserver;
|
protected TextView txtvLength;
|
||||||
private VideoControlsHider videoControlsToggler;
|
protected SeekBar sbPosition;
|
||||||
|
protected ImageButton butPlay;
|
||||||
|
protected ImageButton butRev;
|
||||||
|
protected ImageButton butFF;
|
||||||
|
|
||||||
private FeedMedia media;
|
@Override
|
||||||
private PlayerStatus status;
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
private FeedManager manager;
|
super.onCreate(savedInstanceState);
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Creating Activity");
|
||||||
|
StorageUtils.checkStorageAvailability(this);
|
||||||
|
|
||||||
// Widgets
|
orientation = getResources().getConfiguration().orientation;
|
||||||
private CoverFragment coverFragment;
|
manager = FeedManager.getInstance();
|
||||||
private ItemDescriptionFragment descriptionFragment;
|
getWindow().setFormat(PixelFormat.TRANSPARENT);
|
||||||
private ViewPager viewpager;
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
private TabPageIndicator tabs;
|
bindToService();
|
||||||
private MediaPlayerPagerAdapter pagerAdapter;
|
}
|
||||||
private VideoView videoview;
|
|
||||||
private TextView txtvStatus;
|
protected OnClickListener playbuttonListener = new OnClickListener() {
|
||||||
private TextView txtvPosition;
|
@Override
|
||||||
private TextView txtvLength;
|
public void onClick(View v) {
|
||||||
private SeekBar sbPosition;
|
if (status == PlayerStatus.PLAYING) {
|
||||||
private ImageButton butPlay;
|
playbackService.pause(true);
|
||||||
private ImageButton butRev;
|
} else if (status == PlayerStatus.PAUSED
|
||||||
private ImageButton butFF;
|
|| status == PlayerStatus.PREPARED) {
|
||||||
private LinearLayout videoOverlay;
|
playbackService.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
protected ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||||
|
playbackService = ((PlaybackService.LocalBinder) service)
|
||||||
|
.getService();
|
||||||
|
|
||||||
|
registerReceiver(statusUpdate, new IntentFilter(
|
||||||
|
PlaybackService.ACTION_PLAYER_STATUS_CHANGED));
|
||||||
|
|
||||||
|
registerReceiver(notificationReceiver, new IntentFilter(
|
||||||
|
PlaybackService.ACTION_PLAYER_NOTIFICATION));
|
||||||
|
|
||||||
|
queryService();
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Connection to Service established");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
|
playbackService = null;
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Disconnected from Service");
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
protected BroadcastReceiver statusUpdate = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Received statusUpdate Intent.");
|
||||||
|
status = playbackService.getStatus();
|
||||||
|
handleStatus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
protected BroadcastReceiver notificationReceiver = new BroadcastReceiver() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
int type = intent.getIntExtra(
|
||||||
|
PlaybackService.EXTRA_NOTIFICATION_TYPE, -1);
|
||||||
|
int code = intent.getIntExtra(
|
||||||
|
PlaybackService.EXTRA_NOTIFICATION_CODE, -1);
|
||||||
|
if (code != -1 && type != -1) {
|
||||||
|
switch (type) {
|
||||||
|
case PlaybackService.NOTIFICATION_TYPE_ERROR:
|
||||||
|
handleError(code);
|
||||||
|
break;
|
||||||
|
case PlaybackService.NOTIFICATION_TYPE_BUFFER_UPDATE:
|
||||||
|
if (sbPosition != null) {
|
||||||
|
float progress = ((float) code) / 100;
|
||||||
|
sbPosition.setSecondaryProgress((int) progress
|
||||||
|
* sbPosition.getMax());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PlaybackService.NOTIFICATION_TYPE_RELOAD:
|
||||||
|
if (positionObserver != null) {
|
||||||
|
positionObserver.cancel(true);
|
||||||
|
positionObserver = null;
|
||||||
|
}
|
||||||
|
mediaInfoLoaded = false;
|
||||||
|
queryService();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case PlaybackService.NOTIFICATION_TYPE_SLEEPTIMER_UPDATE:
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Bad arguments. Won't handle intent");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Current screen orientation. */
|
||||||
|
protected int orientation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
@ -231,45 +302,11 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
if (AppConfig.DEBUG)
|
// ignore orientation change
|
||||||
Log.d(TAG, "Configuration changed");
|
|
||||||
orientation = newConfig.orientation;
|
|
||||||
if (positionObserver != null) {
|
|
||||||
positionObserver.cancel(true);
|
|
||||||
}
|
|
||||||
setupGUI();
|
|
||||||
handleStatus();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void bindToService() {
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
if (PlaybackService.isRunning && playbackService != null
|
|
||||||
&& playbackService.isPlayingVideo()) {
|
|
||||||
playbackService.stop();
|
|
||||||
}
|
|
||||||
if (videoControlsToggler != null) {
|
|
||||||
videoControlsToggler.cancel(true);
|
|
||||||
}
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Creating Activity");
|
|
||||||
StorageUtils.checkStorageAvailability(this);
|
|
||||||
|
|
||||||
orientation = getResources().getConfiguration().orientation;
|
|
||||||
manager = FeedManager.getInstance();
|
|
||||||
getWindow().setFormat(PixelFormat.TRANSPARENT);
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
bindToService();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindToService() {
|
|
||||||
Intent serviceIntent = new Intent(this, PlaybackService.class);
|
Intent serviceIntent = new Intent(this, PlaybackService.class);
|
||||||
boolean bound = false;
|
boolean bound = false;
|
||||||
if (!PlaybackService.isRunning) {
|
if (!PlaybackService.isRunning) {
|
||||||
@ -310,10 +347,10 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
switch (status) {
|
switch (status) {
|
||||||
|
|
||||||
case ERROR:
|
case ERROR:
|
||||||
setStatusMsg(R.string.player_error_msg, View.VISIBLE);
|
postStatusMsg(R.string.player_error_msg);
|
||||||
break;
|
break;
|
||||||
case PAUSED:
|
case PAUSED:
|
||||||
setStatusMsg(R.string.player_paused_msg, View.VISIBLE);
|
postStatusMsg(R.string.player_paused_msg);
|
||||||
loadMediaInfo();
|
loadMediaInfo();
|
||||||
if (positionObserver != null) {
|
if (positionObserver != null) {
|
||||||
positionObserver.cancel(true);
|
positionObserver.cancel(true);
|
||||||
@ -322,40 +359,45 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
butPlay.setImageResource(R.drawable.av_play);
|
butPlay.setImageResource(R.drawable.av_play);
|
||||||
break;
|
break;
|
||||||
case PLAYING:
|
case PLAYING:
|
||||||
setStatusMsg(R.string.player_playing_msg, View.INVISIBLE);
|
clearStatusMsg();
|
||||||
loadMediaInfo();
|
loadMediaInfo();
|
||||||
setupPositionObserver();
|
setupPositionObserver();
|
||||||
butPlay.setImageResource(R.drawable.av_pause);
|
butPlay.setImageResource(R.drawable.av_pause);
|
||||||
break;
|
break;
|
||||||
case PREPARING:
|
case PREPARING:
|
||||||
setStatusMsg(R.string.player_preparing_msg, View.VISIBLE);
|
postStatusMsg(R.string.player_preparing_msg);
|
||||||
loadMediaInfo();
|
loadMediaInfo();
|
||||||
break;
|
break;
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
setStatusMsg(R.string.player_stopped_msg, View.VISIBLE);
|
postStatusMsg(R.string.player_stopped_msg);
|
||||||
break;
|
break;
|
||||||
case PREPARED:
|
case PREPARED:
|
||||||
loadMediaInfo();
|
loadMediaInfo();
|
||||||
setStatusMsg(R.string.player_ready_msg, View.VISIBLE);
|
postStatusMsg(R.string.player_ready_msg);
|
||||||
butPlay.setImageResource(R.drawable.av_play);
|
butPlay.setImageResource(R.drawable.av_play);
|
||||||
break;
|
break;
|
||||||
case SEEKING:
|
case SEEKING:
|
||||||
setStatusMsg(R.string.player_seeking_msg, View.VISIBLE);
|
postStatusMsg(R.string.player_seeking_msg);
|
||||||
break;
|
break;
|
||||||
case AWAITING_VIDEO_SURFACE:
|
case AWAITING_VIDEO_SURFACE:
|
||||||
if (AppConfig.DEBUG)
|
onAwaitingVideoSurface();
|
||||||
Log.d(TAG, "Preparing video playback");
|
break;
|
||||||
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStatusMsg(int resId, int visibility) {
|
protected abstract void onAwaitingVideoSurface();
|
||||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
||||||
if (visibility == View.VISIBLE) {
|
protected abstract void postStatusMsg(int resId);
|
||||||
txtvStatus.setText(resId);
|
|
||||||
}
|
protected abstract void clearStatusMsg();
|
||||||
txtvStatus.setVisibility(visibility);
|
|
||||||
}
|
protected void onPositionObserverUpdate() {
|
||||||
|
int currentPosition = playbackService.getPlayer().getCurrentPosition();
|
||||||
|
media.setPosition(currentPosition);
|
||||||
|
txtvPosition.setText(Converter.getDurationStringLong(currentPosition));
|
||||||
|
txtvLength.setText(Converter.getDurationStringLong(playbackService
|
||||||
|
.getPlayer().getDuration()));
|
||||||
|
updateProgressbarPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@ -368,16 +410,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(Void... v) {
|
protected void onProgressUpdate(Void... v) {
|
||||||
super.onProgressUpdate();
|
super.onProgressUpdate();
|
||||||
int currentPosition = playbackService.getPlayer()
|
onPositionObserverUpdate();
|
||||||
.getCurrentPosition();
|
|
||||||
media.setPosition(currentPosition);
|
|
||||||
txtvPosition.setText(Converter
|
|
||||||
.getDurationStringLong(currentPosition));
|
|
||||||
txtvLength.setText(Converter
|
|
||||||
.getDurationStringLong(playbackService.getPlayer()
|
|
||||||
.getDuration()));
|
|
||||||
updateProgressbarPosition();
|
|
||||||
pagerAdapter.notifyMediaPositionChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -401,7 +434,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
sbPosition.setProgress((int) (progress * sbPosition.getMax()));
|
sbPosition.setProgress((int) (progress * sbPosition.getMax()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMediaInfo() {
|
protected void loadMediaInfo() {
|
||||||
if (!mediaInfoLoaded) {
|
if (!mediaInfoLoaded) {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Loading media info");
|
Log.d(TAG, "Loading media info");
|
||||||
@ -409,11 +442,6 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
getSupportActionBar().setSubtitle(media.getItem().getTitle());
|
getSupportActionBar().setSubtitle(media.getItem().getTitle());
|
||||||
getSupportActionBar().setTitle(
|
getSupportActionBar().setTitle(
|
||||||
media.getItem().getFeed().getTitle());
|
media.getItem().getFeed().getTitle());
|
||||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
||||||
pagerAdapter.notifyDataSetChanged();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
txtvPosition.setText(Converter.getDurationStringLong((media
|
txtvPosition.setText(Converter.getDurationStringLong((media
|
||||||
.getPosition())));
|
.getPosition())));
|
||||||
|
|
||||||
@ -430,7 +458,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupGUI() {
|
protected void setupGUI() {
|
||||||
setContentView(R.layout.mediaplayer_activity);
|
setContentView(R.layout.mediaplayer_activity);
|
||||||
sbPosition = (SeekBar) findViewById(R.id.sbPosition);
|
sbPosition = (SeekBar) findViewById(R.id.sbPosition);
|
||||||
txtvPosition = (TextView) findViewById(R.id.txtvPosition);
|
txtvPosition = (TextView) findViewById(R.id.txtvPosition);
|
||||||
@ -497,21 +525,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// PORTRAIT ORIENTATION SETUP
|
|
||||||
|
|
||||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
txtvStatus = (TextView) findViewById(R.id.txtvStatus);
|
|
||||||
viewpager = (ViewPager) findViewById(R.id.viewpager);
|
|
||||||
tabs = (TabPageIndicator) findViewById(R.id.tabs);
|
|
||||||
|
|
||||||
int tabcount = 2;
|
|
||||||
if (media != null && media.getItem().getSimpleChapters() != null) {
|
|
||||||
tabcount = 3;
|
|
||||||
}
|
|
||||||
pagerAdapter = new MediaPlayerPagerAdapter(
|
|
||||||
getSupportFragmentManager(), tabcount, this);
|
|
||||||
viewpager.setAdapter(pagerAdapter);
|
|
||||||
tabs.setViewPager(viewpager);
|
|
||||||
} else {
|
} else {
|
||||||
videoOverlay = (LinearLayout) findViewById(R.id.overlay);
|
videoOverlay = (LinearLayout) findViewById(R.id.overlay);
|
||||||
videoview = (VideoView) findViewById(R.id.videoview);
|
videoview = (VideoView) findViewById(R.id.videoview);
|
||||||
@ -524,64 +539,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnClickListener playbuttonListener = new OnClickListener() {
|
void handleError(int errorCode) {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (status == PlayerStatus.PLAYING) {
|
|
||||||
playbackService.pause(true);
|
|
||||||
} else if (status == PlayerStatus.PAUSED
|
|
||||||
|| status == PlayerStatus.PREPARED) {
|
|
||||||
playbackService.play();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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();
|
|
||||||
if (videoControlsShowing) {
|
|
||||||
setupVideoControlsToggler();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
private void setupVideoControlsToggler() {
|
|
||||||
if (videoControlsToggler != null) {
|
|
||||||
videoControlsToggler.cancel(true);
|
|
||||||
}
|
|
||||||
videoControlsToggler = new VideoControlsHider();
|
|
||||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
|
||||||
videoControlsToggler
|
|
||||||
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
} else {
|
|
||||||
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(int errorCode) {
|
|
||||||
final AlertDialog.Builder errorDialog = new AlertDialog.Builder(this);
|
final AlertDialog.Builder errorDialog = new AlertDialog.Builder(this);
|
||||||
errorDialog.setTitle(R.string.error_label);
|
errorDialog.setTitle(R.string.error_label);
|
||||||
errorDialog
|
errorDialog
|
||||||
@ -597,36 +555,11 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
errorDialog.create().show();
|
errorDialog.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
|
||||||
playbackService = ((PlaybackService.LocalBinder) service)
|
|
||||||
.getService();
|
|
||||||
|
|
||||||
registerReceiver(statusUpdate, new IntentFilter(
|
|
||||||
PlaybackService.ACTION_PLAYER_STATUS_CHANGED));
|
|
||||||
|
|
||||||
registerReceiver(notificationReceiver, new IntentFilter(
|
|
||||||
PlaybackService.ACTION_PLAYER_NOTIFICATION));
|
|
||||||
|
|
||||||
queryService();
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Connection to Service established");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
|
||||||
playbackService = null;
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Disconnected from Service");
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when connection to playback service has been established or
|
* Called when connection to playback service has been established or
|
||||||
* information has to be refreshed
|
* information has to be refreshed
|
||||||
*/
|
*/
|
||||||
private void queryService() {
|
void queryService() {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Querying service info");
|
Log.d(TAG, "Querying service info");
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
@ -660,183 +593,6 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BroadcastReceiver statusUpdate = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Received statusUpdate Intent.");
|
|
||||||
status = playbackService.getStatus();
|
|
||||||
handleStatus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private BroadcastReceiver notificationReceiver = new BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
int type = intent.getIntExtra(
|
|
||||||
PlaybackService.EXTRA_NOTIFICATION_TYPE, -1);
|
|
||||||
int code = intent.getIntExtra(
|
|
||||||
PlaybackService.EXTRA_NOTIFICATION_CODE, -1);
|
|
||||||
if (code != -1 && type != -1) {
|
|
||||||
switch (type) {
|
|
||||||
case PlaybackService.NOTIFICATION_TYPE_ERROR:
|
|
||||||
handleError(code);
|
|
||||||
break;
|
|
||||||
case PlaybackService.NOTIFICATION_TYPE_BUFFER_UPDATE:
|
|
||||||
if (sbPosition != null) {
|
|
||||||
float progress = ((float) code) / 100;
|
|
||||||
sbPosition.setSecondaryProgress((int) progress
|
|
||||||
* sbPosition.getMax());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PlaybackService.NOTIFICATION_TYPE_RELOAD:
|
|
||||||
if (positionObserver != null) {
|
|
||||||
positionObserver.cancel(true);
|
|
||||||
positionObserver = null;
|
|
||||||
}
|
|
||||||
mediaInfoLoaded = false;
|
|
||||||
queryService();
|
|
||||||
|
|
||||||
break;
|
|
||||||
case PlaybackService.NOTIFICATION_TYPE_SLEEPTIMER_UPDATE:
|
|
||||||
invalidateOptionsMenu();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Bad arguments. Won't handle intent");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
private boolean holderCreated;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void surfaceChanged(SurfaceHolder holder, int format, int width,
|
|
||||||
int height) {
|
|
||||||
holder.setFixedSize(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
|
||||||
holderCreated = true;
|
|
||||||
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) {
|
|
||||||
holderCreated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MediaPlayerPagerAdapter extends
|
|
||||||
FragmentStatePagerAdapter {
|
|
||||||
private int numItems;
|
|
||||||
private MediaplayerActivity activity;
|
|
||||||
|
|
||||||
private SherlockListFragment sCChapterFragment;
|
|
||||||
|
|
||||||
private static final int POS_COVER = 0;
|
|
||||||
private static final int POS_DESCR = 1;
|
|
||||||
private static final int POS_CHAPTERS = 2;
|
|
||||||
|
|
||||||
public MediaPlayerPagerAdapter(FragmentManager fm, int numItems,
|
|
||||||
MediaplayerActivity activity) {
|
|
||||||
super(fm);
|
|
||||||
this.numItems = numItems;
|
|
||||||
this.activity = activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fragment getItem(int position) {
|
|
||||||
if (activity.media != null) {
|
|
||||||
switch (position) {
|
|
||||||
case POS_COVER:
|
|
||||||
activity.coverFragment = CoverFragment
|
|
||||||
.newInstance(activity.media.getItem());
|
|
||||||
return activity.coverFragment;
|
|
||||||
case POS_DESCR:
|
|
||||||
activity.descriptionFragment = ItemDescriptionFragment
|
|
||||||
.newInstance(activity.media.getItem());
|
|
||||||
return activity.descriptionFragment;
|
|
||||||
case POS_CHAPTERS:
|
|
||||||
sCChapterFragment = new SherlockListFragment() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onListItemClick(ListView l, View v,
|
|
||||||
int position, long id) {
|
|
||||||
super.onListItemClick(l, v, position, id);
|
|
||||||
SimpleChapter chapter = (SimpleChapter) this
|
|
||||||
.getListAdapter().getItem(position);
|
|
||||||
if (activity.playbackService != null) {
|
|
||||||
activity.playbackService.seekToChapter(chapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
sCChapterFragment.setListAdapter(new SCListAdapter(
|
|
||||||
activity, 0, activity.media.getItem()
|
|
||||||
.getSimpleChapters()));
|
|
||||||
|
|
||||||
return sCChapterFragment;
|
|
||||||
default:
|
|
||||||
return CoverFragment.newInstance(null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return CoverFragment.newInstance(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getPageTitle(int position) {
|
|
||||||
switch (position) {
|
|
||||||
case POS_COVER:
|
|
||||||
return activity.getString(R.string.cover_label);
|
|
||||||
case POS_DESCR:
|
|
||||||
return activity.getString(R.string.shownotes_label);
|
|
||||||
case POS_CHAPTERS:
|
|
||||||
return activity.getString(R.string.chapters_label);
|
|
||||||
default:
|
|
||||||
return super.getPageTitle(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return numItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemPosition(Object object) {
|
|
||||||
return POSITION_UNCHANGED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notifyMediaPositionChanged() {
|
|
||||||
if (sCChapterFragment != null) {
|
|
||||||
ArrayAdapter<SimpleChapter> adapter = (ArrayAdapter<SimpleChapter>) sCChapterFragment
|
|
||||||
.getListAdapter();
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------- ASYNC TASKS
|
|
||||||
|
|
||||||
/** Refreshes the current position of the media file that is playing. */
|
/** Refreshes the current position of the media file that is playing. */
|
||||||
public class MediaPositionObserver extends
|
public class MediaPositionObserver extends
|
||||||
AsyncTask<MediaPlayer, Void, Void> {
|
AsyncTask<MediaPlayer, Void, Void> {
|
||||||
@ -879,43 +635,4 @@ 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 = 5000;
|
|
||||||
private static final String TAG = "VideoControlsToggler";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onProgressUpdate(Void... values) {
|
|
||||||
if (videoControlsShowing) {
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Hiding video controls");
|
|
||||||
getSupportActionBar().hide();
|
|
||||||
videoOverlay.setVisibility(View.GONE);
|
|
||||||
videoControlsShowing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... params) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(WAITING_INTERVALL);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
publishProgress();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.activity.MediaplayerActivity;
|
import de.danoeh.antennapod.activity.AudioplayerActivity;
|
||||||
import de.danoeh.antennapod.asynctask.DownloadStatus;
|
import de.danoeh.antennapod.asynctask.DownloadStatus;
|
||||||
import de.danoeh.antennapod.service.PlaybackService;
|
import de.danoeh.antennapod.service.PlaybackService;
|
||||||
import de.danoeh.antennapod.storage.*;
|
import de.danoeh.antennapod.storage.*;
|
||||||
@ -106,7 +106,7 @@ public class FeedManager {
|
|||||||
context.startService(launchIntent);
|
context.startService(launchIntent);
|
||||||
if (showPlayer) {
|
if (showPlayer) {
|
||||||
// Launch Mediaplayer
|
// Launch Mediaplayer
|
||||||
Intent playerIntent = new Intent(context, MediaplayerActivity.class);
|
Intent playerIntent = new Intent(context, AudioplayerActivity.class);
|
||||||
context.startActivity(playerIntent);
|
context.startActivity(playerIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import org.xml.sax.SAXException;
|
|||||||
|
|
||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.activity.DownloadActivity;
|
import de.danoeh.antennapod.activity.DownloadActivity;
|
||||||
import de.danoeh.antennapod.activity.MediaplayerActivity;
|
import de.danoeh.antennapod.activity.AudioplayerActivity;
|
||||||
import de.danoeh.antennapod.activity.MainActivity;
|
import de.danoeh.antennapod.activity.MainActivity;
|
||||||
import de.danoeh.antennapod.asynctask.DownloadObserver;
|
import de.danoeh.antennapod.asynctask.DownloadObserver;
|
||||||
import de.danoeh.antennapod.asynctask.DownloadStatus;
|
import de.danoeh.antennapod.asynctask.DownloadStatus;
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import android.view.SurfaceHolder;
|
|||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.PodcastApp;
|
import de.danoeh.antennapod.PodcastApp;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.MediaplayerActivity;
|
import de.danoeh.antennapod.activity.AudioplayerActivity;
|
||||||
import de.danoeh.antennapod.feed.Feed;
|
import de.danoeh.antennapod.feed.Feed;
|
||||||
import de.danoeh.antennapod.feed.FeedItem;
|
import de.danoeh.antennapod.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.feed.FeedManager;
|
import de.danoeh.antennapod.feed.FeedManager;
|
||||||
@ -563,7 +563,7 @@ public class PlaybackService extends Service {
|
|||||||
/** Prepares notification and starts the service in the foreground. */
|
/** Prepares notification and starts the service in the foreground. */
|
||||||
private void setupNotification() {
|
private void setupNotification() {
|
||||||
PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(
|
PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(
|
||||||
this, MediaplayerActivity.class),
|
this, AudioplayerActivity.class),
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
Bitmap icon = BitmapFactory.decodeResource(null,
|
Bitmap icon = BitmapFactory.decodeResource(null,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import android.util.Log;
|
|||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
import de.danoeh.antennapod.activity.MediaplayerActivity;
|
import de.danoeh.antennapod.activity.AudioplayerActivity;
|
||||||
import de.danoeh.antennapod.feed.FeedMedia;
|
import de.danoeh.antennapod.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.receiver.MediaButtonReceiver;
|
import de.danoeh.antennapod.receiver.MediaButtonReceiver;
|
||||||
import de.danoeh.antennapod.receiver.PlayerWidget;
|
import de.danoeh.antennapod.receiver.PlayerWidget;
|
||||||
@ -68,7 +68,7 @@ public class PlayerWidgetService extends Service {
|
|||||||
RemoteViews views = new RemoteViews(getPackageName(),
|
RemoteViews views = new RemoteViews(getPackageName(),
|
||||||
R.layout.player_widget);
|
R.layout.player_widget);
|
||||||
PendingIntent startMediaplayer = PendingIntent.getActivity(this, 0,
|
PendingIntent startMediaplayer = PendingIntent.getActivity(this, 0,
|
||||||
new Intent(this, MediaplayerActivity.class), 0);
|
new Intent(this, AudioplayerActivity.class), 0);
|
||||||
|
|
||||||
views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
|
views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user