Implemented Videoplayer
This commit is contained in:
parent
c1dcfe7aa6
commit
1972652cb1
|
@ -1,69 +1,34 @@
|
|||
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 {
|
||||
public class AudioplayerActivity extends MediaplayerActivity {
|
||||
|
||||
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() {
|
||||
|
@ -115,79 +80,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -282,44 +175,6 @@ public class AudioplayerActivity extends MediaplayerActivity implements
|
|||
|
||||
}
|
||||
|
||||
// ---------------------- 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,29 +17,22 @@ import android.media.MediaPlayer;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.TextView;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.viewpagerindicator.TabPageIndicator;
|
||||
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.PodcastApp;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.AudioplayerActivity.MediaPlayerPagerAdapter;
|
||||
import de.danoeh.antennapod.activity.AudioplayerActivity.MediaPositionObserver;
|
||||
import de.danoeh.antennapod.dialog.TimeDialog;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.feed.FeedMedia;
|
||||
|
@ -524,19 +517,6 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
|
||||
} else {
|
||||
videoOverlay = (LinearLayout) findViewById(R.id.overlay);
|
||||
videoview = (VideoView) findViewById(R.id.videoview);
|
||||
videoview.getHolder().addCallback(this);
|
||||
videoview.setOnClickListener(playbuttonListener);
|
||||
videoview.setOnTouchListener(onVideoviewTouched);
|
||||
setupVideoControlsToggler();
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
|
||||
void handleError(int errorCode) {
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.service.PlaybackService;
|
||||
import de.danoeh.antennapod.service.PlayerStatus;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.VideoView;
|
||||
|
||||
public class VideoplayerActivity extends MediaplayerActivity implements
|
||||
SurfaceHolder.Callback {
|
||||
private static final String TAG = "VideoplayerActivity";
|
||||
|
||||
/** True if video controls are currently visible. */
|
||||
private boolean videoControlsShowing = true;
|
||||
private VideoControlsHider videoControlsToggler;
|
||||
|
||||
private LinearLayout videoOverlay;
|
||||
private VideoView videoview;
|
||||
|
||||
@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 setupGUI() {
|
||||
super.setupGUI();
|
||||
videoOverlay = (LinearLayout) findViewById(R.id.overlay);
|
||||
videoview = (VideoView) findViewById(R.id.videoview);
|
||||
videoview.getHolder().addCallback(this);
|
||||
videoview.setOnClickListener(playbuttonListener);
|
||||
videoview.setOnTouchListener(onVideoviewTouched);
|
||||
setupVideoControlsToggler();
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onAwaitingVideoSurface() {
|
||||
playbackService.setVideoSurface(videoview.getHolder());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postStatusMsg(int resId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearStatusMsg() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@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
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue