From: tobiasKaminsky Date: Fri, 13 Nov 2015 16:39:24 +0000 (+0100) Subject: Merge remote-tracking branch 'remotes/upstream/master' into beta X-Git-Tag: beta-20151122~27 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7d6a3630aebda914cd053b3c6f577ac4cb69ef7a Merge remote-tracking branch 'remotes/upstream/master' into beta --- 7d6a3630aebda914cd053b3c6f577ac4cb69ef7a diff --cc src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index a749b5ce,8f813b86..a047ab36 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@@ -279,10 -266,10 +277,10 @@@ public class PreviewMediaFragment exten @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(); @@@ -450,67 -437,9 +448,67 @@@ // load the video file in the video player ; // when done, VideoHelper#onPrepared() will be called + if (getFile().isDown()) { + mUri = getFile().getStoragePath(); + } else { + Context context = MainApp.getAppContext(); + Account account = mContainerActivity.getStorageManager().getAccount(); + + mUri = generateUrlWithCredentials(account, context, getFile()); + } + - mVideoPreview.setVideoPath(mUri); + 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 { + @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 { @@@ -576,14 -489,31 +558,14 @@@ */ @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(); } diff --cc src/com/owncloud/android/ui/preview/PreviewVideoActivity.java index 383b0828,8972f3c2..c1b4125e --- a/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java @@@ -204,14 -203,19 +203,14 @@@ public class PreviewVideoActivity exten 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);