@Override
public void onStart() {
super.onStart();
- Log_OC.e(TAG, "onStart");
+ Log_OC.v(TAG, "onStart");
OCFile file = getFile();
- if (file != null && file.isDown()) {
+ if (file != null) {
if (file.isAudio()) {
bindMediaService();
// load the video file in the video player ;
// when done, VideoHelper#onPrepared() will be called
- mVideoPreview.setVideoPath(mUri);
+ if (getFile().isDown()) {
+ mUri = getFile().getStoragePath();
+ } else {
+ Context context = MainApp.getAppContext();
+ Account account = mContainerActivity.getStorageManager().getAccount();
+
+ mUri = generateUrlWithCredentials(account, context, getFile());
+ }
+
+ mVideoPreview.setVideoURI(getFile().getStorageUri());
}
+ public static String generateUrlWithCredentials(Account account, Context context, OCFile file){
+ OwnCloudAccount ocAccount = null;
+ try {
+ ocAccount = new OwnCloudAccount(account, context);
+
+ final ClientGenerationTask task = new ClientGenerationTask();
+ task.execute(ocAccount);
+
+ OwnCloudClient mClient = task.get();
+ String url = AccountUtils.constructFullURLForAccount(context, account) + Uri.encode(file.getRemotePath(), "/");
+ OwnCloudCredentials credentials = mClient.getCredentials();
+
+ return url.replace("//", "//" + credentials.getUsername() + ":" + credentials.getAuthToken() + "@");
+
+ } catch (AccountUtils.AccountNotFoundException e) {
+ e.printStackTrace();
+
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ return "";
+ }
+
+ public static class ClientGenerationTask extends AsyncTask<Object, Void, OwnCloudClient> {
+ @Override
+ protected OwnCloudClient doInBackground(Object... params) {
+ Object account = params[0];
+ if (account instanceof OwnCloudAccount){
+ try {
+ OwnCloudAccount ocAccount = (OwnCloudAccount) account;
+ return OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, MainApp.getAppContext());
+ } catch (AccountUtils.AccountNotFoundException e) {
+ e.printStackTrace();
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (AuthenticatorException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return null;
+ }
+ }
+
private class VideoHelper implements OnCompletionListener, OnPreparedListener, OnErrorListener {
*/
@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);
- new AlertDialog.Builder(getActivity())
- .setMessage(message)
- .setPositiveButton(android.R.string.VideoView_error_button,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- dialog.dismiss();
- VideoHelper.this.onCompletion(null);
- }
- })
- .setCancelable(false)
- .show();
- }
+ MediaService.streamWithExternalApp(mUri, getActivity()).show();
return true;
}
-
}
-
@Override
public void onPause() {
- Log_OC.e(TAG, "onPause");
+ Log_OC.v(TAG, "onPause");
super.onPause();
}
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;
- try {
- url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath();
- mVideoPlayer.setVideoURI(Uri.parse(url));
- } catch (AccountNotFoundException e) {
- onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
- }
+ url = PreviewMediaFragment.generateUrlWithCredentials(getAccount(), getApplicationContext(), getFile());
+ mVideoPlayer.setVideoURI(Uri.parse(url));
}
-
+
// create and prepare control panel for the user
mMediaController = new MediaController(this);
mMediaController.setMediaPlayer(mVideoPlayer);