mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Merge pull request #1269 from owncloud/fix_video_not_previewed
Fix video not previewed #1180
This commit is contained in:
commit
80aacce3f3
3 changed files with 53 additions and 43 deletions
|
@ -1,6 +1,8 @@
|
|||
/**
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author Bartek Przybylski
|
||||
* @author David A. Velasco
|
||||
* Copyright (C) 2012 Bartek Przybylski
|
||||
* Copyright (C) 2015 ownCloud Inc.
|
||||
*
|
||||
|
@ -20,6 +22,8 @@
|
|||
|
||||
package com.owncloud.android.datamodel;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
@ -80,6 +84,12 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
|
||||
private boolean mShareWithSharee;
|
||||
|
||||
/**
|
||||
* URI to the local path of the file contents, if stored in the device; cached after first call
|
||||
* to {@link #getStorageUri()}
|
||||
*/
|
||||
private Uri mLocalUri;
|
||||
|
||||
|
||||
/**
|
||||
* Create new {@link OCFile} with given path.
|
||||
|
@ -213,6 +223,24 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
return mLocalPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* The URI to the file contents, if stored locally
|
||||
*
|
||||
* @return A URI to the local copy of the file, or NULL if not stored in the device
|
||||
*/
|
||||
public Uri getStorageUri() {
|
||||
if (mLocalPath == null || mLocalPath.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (mLocalUri == null) {
|
||||
Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme(ContentResolver.SCHEME_FILE);
|
||||
builder.path(mLocalPath);
|
||||
mLocalUri = builder.build();
|
||||
}
|
||||
return mLocalUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to set the path where the file is stored
|
||||
*
|
||||
|
@ -220,6 +248,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
*/
|
||||
public void setStoragePath(String storage_path) {
|
||||
mLocalPath = storage_path;
|
||||
mLocalUri = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,8 +36,6 @@ 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.IBinder;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -153,7 +151,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
Log_OC.e(TAG, "onCreateView");
|
||||
Log_OC.v(TAG, "onCreateView");
|
||||
|
||||
|
||||
mView = inflater.inflate(R.layout.file_preview, container, false);
|
||||
|
@ -174,7 +172,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
Log_OC.e(TAG, "onActivityCreated");
|
||||
Log_OC.v(TAG, "onActivityCreated");
|
||||
|
||||
OCFile file = getFile();
|
||||
if (savedInstanceState == null) {
|
||||
|
@ -244,7 +242,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
Log_OC.e(TAG, "onSaveInstanceState");
|
||||
Log_OC.v(TAG, "onSaveInstanceState");
|
||||
|
||||
outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, getFile());
|
||||
outState.putParcelable(PreviewMediaFragment.EXTRA_ACCOUNT, mAccount);
|
||||
|
@ -268,7 +266,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Log_OC.e(TAG, "onStart");
|
||||
Log_OC.v(TAG, "onStart");
|
||||
|
||||
OCFile file = getFile();
|
||||
if (file != null && file.isDown()) {
|
||||
|
@ -402,7 +400,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
/**
|
||||
* Update the file of the fragment with file value
|
||||
*
|
||||
* @param file
|
||||
* @param file Replaces the held file with a new one
|
||||
*/
|
||||
public void updateFile(OCFile file) {
|
||||
setFile(file);
|
||||
|
@ -439,8 +437,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
|
||||
// load the video file in the video player ;
|
||||
// when done, VideoHelper#onPrepared() will be called
|
||||
Uri uri = Uri.parse(getFile().getStoragePath());
|
||||
mVideoPreview.setVideoPath(uri.encode(getFile().getStoragePath()));
|
||||
mVideoPreview.setVideoURI(getFile().getStorageUri());
|
||||
}
|
||||
|
||||
|
||||
|
@ -455,7 +452,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
*/
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer vp) {
|
||||
Log_OC.e(TAG, "onPrepared");
|
||||
Log_OC.v(TAG, "onPrepared");
|
||||
mVideoPreview.seekTo(mSavedPlaybackPosition);
|
||||
if (mAutoplay) {
|
||||
mVideoPreview.start();
|
||||
|
@ -475,25 +472,9 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
*/
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
Log_OC.e(TAG, "completed");
|
||||
Log_OC.v(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(getFile().getStoragePath());
|
||||
}
|
||||
}
|
||||
} // else : called from onError()
|
||||
mMediaController.updatePausePlay();
|
||||
}
|
||||
|
@ -508,6 +489,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
*/
|
||||
@Override
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
Log_OC.e(TAG, "Error in video playback, what = " + what + ", extra = " + extra);
|
||||
if (mVideoPreview.getWindowToken() != null) {
|
||||
String message = MediaService.getMessageForMediaError(
|
||||
getActivity(), what, extra);
|
||||
|
@ -531,25 +513,25 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
|
||||
@Override
|
||||
public void onPause() {
|
||||
Log_OC.e(TAG, "onPause");
|
||||
Log_OC.v(TAG, "onPause");
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Log_OC.e(TAG, "onResume");
|
||||
Log_OC.v(TAG, "onResume");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log_OC.e(TAG, "onDestroy");
|
||||
Log_OC.v(TAG, "onDestroy");
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
Log_OC.e(TAG, "onStop");
|
||||
Log_OC.v(TAG, "onStop");
|
||||
|
||||
mPrepared = false;
|
||||
if (mMediaServiceConnection != null) {
|
||||
|
@ -590,12 +572,12 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
Log_OC.e(TAG, "onConfigurationChanged " + this);
|
||||
Log_OC.v(TAG, "onConfigurationChanged " + this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Log_OC.e(TAG, "onActivityResult " + this);
|
||||
Log_OC.v(TAG, "onActivityResult " + this);
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
mSavedPlaybackPosition = data.getExtras().getInt(
|
||||
|
@ -669,7 +651,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
@Override
|
||||
public void onServiceDisconnected(ComponentName component) {
|
||||
if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
|
||||
Log_OC.e(TAG, "Media service suddenly disconnected");
|
||||
Log_OC.w(TAG, "Media service suddenly disconnected");
|
||||
if (mMediaController != null) {
|
||||
mMediaController.setMediaPlayer(null);
|
||||
}
|
||||
|
@ -733,7 +715,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
if (mPrepared) {
|
||||
mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
|
||||
}
|
||||
Log_OC.e(TAG, "getting position: " + mSavedPlaybackPosition);
|
||||
Log_OC.v(TAG, "getting position: " + mSavedPlaybackPosition);
|
||||
return mSavedPlaybackPosition;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log_OC.e(TAG, "ACTIVITY\t\tonCreate");
|
||||
Log_OC.v(TAG, "onCreate");
|
||||
|
||||
setContentView(R.layout.video_layout);
|
||||
|
||||
|
@ -110,7 +110,6 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi
|
|||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
Log_OC.e(TAG, "ACTIVITY\t\tonSaveInstanceState");
|
||||
outState.putInt(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPlayer.getCurrentPosition());
|
||||
outState.putBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY , mVideoPlayer.isPlaying());
|
||||
}
|
||||
|
@ -118,7 +117,7 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi
|
|||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Log_OC.e(TAG, "ACTIVTIY\t\tonBackPressed");
|
||||
Log_OC.v(TAG, "onBackPressed");
|
||||
Intent i = new Intent();
|
||||
i.putExtra(EXTRA_AUTOPLAY, mVideoPlayer.isPlaying());
|
||||
i.putExtra(EXTRA_START_POSITION, mVideoPlayer.getCurrentPosition());
|
||||
|
@ -136,7 +135,7 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi
|
|||
*/
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
Log_OC.e(TAG, "ACTIVITY\t\tonPrepare");
|
||||
Log_OC.v(TAG, "onPrepare");
|
||||
mVideoPlayer.seekTo(mSavedPlaybackPosition);
|
||||
if (mAutoplay) {
|
||||
mVideoPlayer.start();
|
||||
|
@ -204,8 +203,8 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi
|
|||
file = getStorageManager().getFileById(file.getFileId());
|
||||
if (file != null) {
|
||||
if (file.isDown()) {
|
||||
mVideoPlayer.setVideoPath(file.getStoragePath());
|
||||
|
||||
mVideoPlayer.setVideoURI(file.getStorageUri());
|
||||
|
||||
} else {
|
||||
// not working yet
|
||||
String url;
|
||||
|
@ -216,13 +215,13 @@ public class PreviewVideoActivity extends FileActivity implements OnCompletionLi
|
|||
onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create and prepare control panel for the user
|
||||
mMediaController = new MediaController(this);
|
||||
mMediaController.setMediaPlayer(mVideoPlayer);
|
||||
mMediaController.setAnchorView(mVideoPlayer);
|
||||
mVideoPlayer.setMediaController(mMediaController);
|
||||
|
||||
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue