* Copyright (C) 2012-2013 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import com.owncloud.android.ui.fragment.FileDetailFragment;
import com.owncloud.android.ui.fragment.FileFragment;
+import com.owncloud.android.Log_OC;
import com.owncloud.android.R;
import eu.alefzero.webdav.WebdavClient;
import eu.alefzero.webdav.WebdavUtils;
private MediaServiceConnection mMediaServiceConnection = null;
private VideoHelper mVideoHelper;
private boolean mAutoplay;
+ public boolean mPrepared;
private static final String TAG = PreviewMediaFragment.class.getSimpleName();
* @param fileToDetail An {@link OCFile} to preview in the fragment
* @param ocAccount An ownCloud account; needed to start downloads
*/
- public PreviewMediaFragment(OCFile fileToDetail, Account ocAccount) {
+ public PreviewMediaFragment(OCFile fileToDetail, Account ocAccount, int startPlaybackPosition, boolean autoplay) {
mFile = fileToDetail;
mAccount = ocAccount;
- mSavedPlaybackPosition = 0;
+ mSavedPlaybackPosition = startPlaybackPosition;
mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
- mAutoplay = true;
+ mAutoplay = autoplay;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
+ Log_OC.e(TAG, "onCreateView");
+
mView = inflater.inflate(R.layout.file_preview, container, false);
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
+ Log_OC.e(TAG, "onAttach");
+
if (!(activity instanceof FileFragment.ContainerActivity))
throw new ClassCastException(activity.toString() + " must implement " + FileFragment.ContainerActivity.class.getSimpleName());
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
+ Log_OC.e(TAG, "onActivityCreated");
mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
if (savedInstanceState != null) {
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
+ Log_OC.e(TAG, "onSaveInstanceState");
+
outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, mFile);
outState.putParcelable(PreviewMediaFragment.EXTRA_ACCOUNT, mAccount);
if (mFile.isVideo()) {
- outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mVideoPreview.getCurrentPosition());
- outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING , mVideoPreview.isPlaying());
+ mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
+ mAutoplay = mVideoPreview.isPlaying();
+ outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mSavedPlaybackPosition);
+ outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING , mAutoplay);
} else {
outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mMediaServiceBinder.getCurrentPosition());
outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING , mMediaServiceBinder.isPlaying());
@Override
public void onStart() {
super.onStart();
+ Log_OC.e(TAG, "onStart");
if (mFile != null) {
if (mFile.isAudio()) {
toHide.add(R.id.action_cancel_download);
toHide.add(R.id.action_cancel_upload);
toHide.add(R.id.action_download_file);
+ toHide.add(R.id.action_sync_file);
toHide.add(R.id.action_rename_file); // by now
for (int i : toHide) {
*/
@Override
public void onPrepared(MediaPlayer vp) {
+ Log.e(TAG, "onPrepared");
mVideoPreview.seekTo(mSavedPlaybackPosition);
if (mAutoplay) {
mVideoPreview.start();
}
mMediaController.setEnabled(true);
mMediaController.updatePausePlay();
+ mPrepared = true;
}
*/
@Override
public void onCompletion(MediaPlayer mp) {
- mVideoPreview.seekTo(0);
+ Log.e(TAG, "completed");
+ if (mp != null) {
+ mVideoPreview.seekTo(0);
+ // next lines are necessary to work around undesired video loops
+ if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD) {
+ mVideoPreview.pause();
+
+ } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1) {
+ // mVideePreview.pause() is not enough
+
+ mMediaController.setEnabled(false);
+ mVideoPreview.stopPlayback();
+ mAutoplay = false;
+ mSavedPlaybackPosition = 0;
+ mVideoPreview.setVideoPath(mFile.getStoragePath());
+ }
+ } // else : called from onError()
mMediaController.updatePausePlay();
}
@Override
+ public void onPause() {
+ super.onPause();
+ Log_OC.e(TAG, "onPause");
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ Log_OC.e(TAG, "onResume");
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ Log_OC.e(TAG, "onDestroy");
+ }
+
+ @Override
public void onStop() {
+ Log_OC.e(TAG, "onStop");
super.onStop();
-
+
+ mPrepared = false;
if (mMediaServiceConnection != null) {
Log.d(TAG, "Unbinding from MediaService ...");
if (mMediaServiceBinder != null && mMediaController != null) {
startActivityForResult(i, 0);
}
+ @Override
+ public void onConfigurationChanged (Configuration newConfig) {
+ Log_OC.e(TAG, "onConfigurationChanged " + this);
+ }
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
+ Log_OC.e(TAG, "onActivityResult " + this);
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
mSavedPlaybackPosition = data.getExtras().getInt(PreviewVideoActivity.EXTRA_START_POSITION);
container.finish();
}
}
+
+
+ public int getPosition() {
+ if (mPrepared) {
+ mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
+ }
+ Log_OC.e(TAG, "getting position: " + mSavedPlaybackPosition);
+ return mSavedPlaybackPosition;
+ }
+
+ public boolean isPlaying() {
+ if (mPrepared) {
+ mAutoplay = mVideoPreview.isPlaying();
+ }
+ return mAutoplay;
+ }
}