Improve video errors and loading

This commit is contained in:
Mario Danic 2017-01-23 13:29:13 +01:00 committed by AndyScherzinger
parent d9fa7b616b
commit d8395d57b9
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 123 additions and 58 deletions

View file

@ -19,46 +19,69 @@
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".ui.fragment.FilePreviewFragment">
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".ui.fragment.FilePreviewFragment">
<RelativeLayout
android:id="@+id/file_preview_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible">
<FrameLayout
android:id="@+id/visual_area"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="@+id/media_controller"
android:layout_alignParentTop="true"
>
<ImageView
android:id="@+id/image_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="@dimen/standard_margin"
android:contentDescription="@string/preview_image_description"
android:src="@drawable/logo"/>
<VideoView
android:id="@+id/video_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:visibility="gone"
/>
</FrameLayout>
<com.owncloud.android.media.MediaControlView
android:id="@id/media_controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/standard_margin"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/multi_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/empty_list"/>
</ScrollView>
</RelativeLayout>
<FrameLayout
android:id="@+id/visual_area"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_above="@+id/media_controller"
>
<ImageView
android:id="@+id/image_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/standard_margin"
android:layout_gravity="center"
android:contentDescription="@string/preview_image_description"
android:src="@drawable/logo" />
<VideoView
android:id="@+id/video_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:visibility="gone"
/>
</FrameLayout>
<com.owncloud.android.media.MediaControlView
android:id="@id/media_controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/standard_margin"
/>
</RelativeLayout>

View file

@ -23,7 +23,6 @@ import android.accounts.Account;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Configuration;
@ -37,7 +36,8 @@ import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AlertDialog;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -47,6 +47,10 @@ import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
@ -69,7 +73,7 @@ import com.owncloud.android.utils.MimeTypeUtil;
*
* Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will
* produce an {@link IllegalStateException}.
*
*
* By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is
* generated on instantiation too.
*/
@ -87,6 +91,15 @@ public class PreviewMediaFragment extends FileFragment implements
private VideoView mVideoPreview;
private int mSavedPlaybackPosition;
private RelativeLayout mMultiView;
private RelativeLayout mPreviewContainer;
protected LinearLayout mMultiListContainer;
protected TextView mMultiListMessage;
protected TextView mMultiListHeadline;
protected ImageView mMultiListIcon;
protected ProgressBar mMultiListProgress;
private MediaServiceBinder mMediaServiceBinder = null;
private MediaControlView mMediaController = null;
private MediaServiceConnection mMediaServiceConnection = null;
@ -156,16 +169,50 @@ public class PreviewMediaFragment extends FileFragment implements
mView = inflater.inflate(R.layout.file_preview, container, false);
mPreviewContainer = (RelativeLayout) mView.findViewById(R.id.file_preview_container);
mImagePreview = (ImageView) mView.findViewById(R.id.image_preview);
mVideoPreview = (VideoView) mView.findViewById(R.id.video_preview);
mVideoPreview.setOnTouchListener(this);
mMediaController = (MediaControlView) mView.findViewById(R.id.media_controller);
mMultiView = (RelativeLayout) mView.findViewById(R.id.multi_view);
setupMultiView(mView);
setMultiListLoadingMessage();
return mView;
}
protected void setupMultiView(View view) {
mMultiListContainer = (LinearLayout) view.findViewById(R.id.empty_list_view);
mMultiListMessage = (TextView) view.findViewById(R.id.empty_list_view_text);
mMultiListHeadline = (TextView) view.findViewById(R.id.empty_list_view_headline);
mMultiListIcon = (ImageView) view.findViewById(R.id.empty_list_icon);
mMultiListProgress = (ProgressBar) view.findViewById(R.id.empty_list_progress);
}
private void setMultiListLoadingMessage() {
if (mMultiView != null) {
mMultiListHeadline.setText(R.string.file_list_loading);
mMultiListMessage.setText("");
mMultiListIcon.setVisibility(View.GONE);
mMultiListProgress.setVisibility(View.VISIBLE);
}
}
public void setMessageForMultiList(String headline, @StringRes int message, @DrawableRes int icon) {
if (mMultiListContainer != null && mMultiListMessage != null) {
mMultiListHeadline.setText(headline);
mMultiListMessage.setText(message);
mMultiListIcon.setImageResource(icon);
mMultiListIcon.setVisibility(View.VISIBLE);
mMultiListProgress.setVisibility(View.GONE);
}
}
/**
* {@inheritDoc}
*/
@ -196,6 +243,7 @@ public class PreviewMediaFragment extends FileFragment implements
mAutoplay = savedInstanceState.getBoolean(PreviewMediaFragment.EXTRA_PLAYING);
}
if (file != null && file.isDown()) {
if (MimeTypeUtil.isVideo(file)) {
mVideoPreview.setVisibility(View.VISIBLE);
@ -447,6 +495,8 @@ public class PreviewMediaFragment extends FileFragment implements
@Override
public void onPrepared(MediaPlayer vp) {
Log_OC.v(TAG, "onPrepared");
mMultiView.setVisibility(View.GONE);
mPreviewContainer.setVisibility(View.VISIBLE);
mVideoPreview.seekTo(mSavedPlaybackPosition);
if (mAutoplay) {
mVideoPreview.start();
@ -484,20 +534,12 @@ 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);
mPreviewContainer.setVisibility(View.GONE);
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();
mMultiView.setVisibility(View.VISIBLE);
setMessageForMultiList(message, R.string.preview_sorry, R.drawable.file_movie);
}
return true;
}
@ -548,7 +590,7 @@ public class PreviewMediaFragment extends FileFragment implements
if (event.getX() / Resources.getSystem().getDisplayMetrics().density > 24.0) {
startFullScreenVideo();
}
return true;
return true;
}
return false;
}
@ -604,11 +646,11 @@ public class PreviewMediaFragment extends FileFragment implements
}
getActivity().bindService( new Intent(getActivity(),
MediaService.class),
mMediaServiceConnection,
mMediaServiceConnection,
Context.BIND_AUTO_CREATE);
// follow the flow in MediaServiceConnection#onServiceConnected(...)
}
/** Defines callbacks for service binding, passed to bindService() */
private class MediaServiceConnection implements ServiceConnection {
@ -649,7 +691,7 @@ public class PreviewMediaFragment extends FileFragment implements
else {
Toast.makeText(
getActivity(),
"No media controller to release when disconnected from media service",
"No media controller to release when disconnected from media service",
Toast.LENGTH_SHORT).show();
}
mMediaServiceBinder = null;