Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/error handle #26

Merged
merged 2 commits into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ public SimpleViewHolder(View itemView) {
mPlayable = true;
}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {
@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
mPlayable = false;
return super.onPlaybackError(mp, what, extra);
}

@Override public void onPlaybackStarted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public CustomViewHolder(View itemView) {

}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {

@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
return true;
}

@Override public void onPlaybackInfo(MediaPlayer mp, int what, int extra) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public HorizontalMixedToroVideoViewHolder(View itemView) {
mInfo.setText("Completed");
}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {
super.onPlaybackError(mp, what, extra);
@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
mThumbnail.animate().alpha(1.f).setDuration(250).setListener(new AnimatorListenerAdapter() {
@Override public void onAnimationEnd(Animator animation) {
HorizontalMixedToroVideoViewHolder.super.onPlaybackStopped();
}
}).start();
mInfo.setText("Error: videoId = " + getVideoId());
return super.onPlaybackError(mp, what, extra);
}

@Override protected boolean allowLongPressSupport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public HorizontalSimpleToroVideoViewHolder(View itemView) {
mInfo.setText("Completed");
}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {
super.onPlaybackError(mp, what, extra);
@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
mThumbnail.animate().alpha(1.f).setDuration(250).setListener(new AnimatorListenerAdapter() {
@Override public void onAnimationEnd(Animator animation) {
HorizontalSimpleToroVideoViewHolder.super.onPlaybackStopped();
}
}).start();
mInfo.setText("Error: videoId = " + getVideoId());
return super.onPlaybackError(mp, what, extra);
}

@Override protected boolean allowLongPressSupport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public MixedToroVideoViewHolder(View itemView) {
mInfo.setText("Completed");
}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {
super.onPlaybackError(mp, what, extra);
@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
mThumbnail.animate().alpha(1.f).setDuration(250).setListener(new AnimatorListenerAdapter() {
@Override public void onAnimationEnd(Animator animation) {
MixedToroVideoViewHolder.super.onPlaybackStopped();
}
}).start();
mInfo.setText("Error: videoId = " + getVideoId());
return super.onPlaybackError(mp, what, extra);
}

@Override protected boolean allowLongPressSupport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ public SimpleToroVideoViewHolder(View itemView) {
mInfo.setText("Completed");
}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {
super.onPlaybackError(mp, what, extra);
@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
mThumbnail.animate().alpha(1.f).setDuration(250).setListener(new AnimatorListenerAdapter() {
@Override public void onAnimationEnd(Animator animation) {
SimpleToroVideoViewHolder.super.onPlaybackStopped();
}
}).start();
mInfo.setText("Error: videoId = " + getVideoId());
return super.onPlaybackError(mp, what, extra);
}

@Override protected boolean allowLongPressSupport() {
Expand Down
13 changes: 2 additions & 11 deletions toro/src/main/java/im/ene/lab/toro/AbsVideoViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ public AbsVideoViewHolder(View itemView) {
return 0;
}

@Override public float visibleAreaOffset() {
Rect videoRect = getVideoRect();
Rect parentRect = getRecyclerViewRect();
if (parentRect != null && !parentRect.contains(videoRect) && !parentRect.intersect(videoRect)) {
return 0.f;
}

return mVideoView.getHeight() <= 0 ? 1.f : videoRect.height() / (float) mVideoView.getHeight();
}

@Override public boolean wantsToPlay() {
// Default implementation
return visibleAreaOffset() >= 0.75;
Expand All @@ -134,8 +124,9 @@ public AbsVideoViewHolder(View itemView) {
mPlayable = true;
}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {
@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
mPlayable = false;
return super.onPlaybackError(mp, what, extra);
}

@NonNull @Override public View getVideoView() {
Expand Down
14 changes: 2 additions & 12 deletions toro/src/main/java/im/ene/lab/toro/TextureVideoViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package im.ene.lab.toro;

import android.graphics.Rect;
import android.media.MediaPlayer;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -106,16 +105,6 @@ public TextureVideoViewHolder(View itemView) {
return 0;
}

@Override public float visibleAreaOffset() {
Rect videoRect = getVideoRect();
Rect parentRect = getRecyclerViewRect();
if (parentRect != null && !parentRect.contains(videoRect) && !parentRect.intersect(videoRect)) {
return 0.f;
}

return mVideoView.getHeight() <= 0 ? 1.f : videoRect.height() / (float) mVideoView.getHeight();
}

@Override public boolean wantsToPlay() {
// Default implementation
return visibleAreaOffset() >= 0.75;
Expand All @@ -129,8 +118,9 @@ public TextureVideoViewHolder(View itemView) {
mPlayable = true;
}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {
@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
mPlayable = false;
return super.onPlaybackError(mp, what, extra);
}

@NonNull @Override public View getVideoView() {
Expand Down
4 changes: 2 additions & 2 deletions toro/src/main/java/im/ene/lab/toro/Toro.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ && getStrategy().allowsToPlay(player, parent)) {
}

final boolean onError(ToroPlayer player, MediaPlayer mp, int what, int extra) {
player.onPlaybackError(mp, what, extra);
boolean handle = player.onPlaybackError(mp, what, extra);
for (ToroScrollListener listener : sInstance.mListeners.values()) {
VideoPlayerManager manager = listener.getManager();
if (player.equals(manager.getPlayer())) {
Expand All @@ -388,7 +388,7 @@ final boolean onError(ToroPlayer player, MediaPlayer mp, int what, int extra) {
return true;
}
}
return false;
return handle;
}

final boolean onInfo(ToroPlayer player, MediaPlayer mp, int what, int extra) {
Expand Down
2 changes: 1 addition & 1 deletion toro/src/main/java/im/ene/lab/toro/ToroPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public interface ToroPlayer
* {@link ToroPlayer#onError(MediaPlayer, int, int)} will be called explicitly by Toro, so this
* method will prevent infinite loop
*/
void onPlaybackError(MediaPlayer mp, int what, int extra);
boolean onPlaybackError(MediaPlayer mp, int what, int extra);

/**
* Called from {@link Toro#onError(ToroPlayer, MediaPlayer, int, int)}
Expand Down
3 changes: 2 additions & 1 deletion toro/src/main/java/im/ene/lab/toro/ToroVideoViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ public ToroVideoViewHolder(View itemView) {
mPlayable = true;
}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {
@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
mPlayable = false;
return super.onPlaybackError(mp, what, extra);
}

@NonNull @Override public View getVideoView() {
Expand Down
4 changes: 2 additions & 2 deletions toro/src/main/java/im/ene/lab/toro/ToroViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ protected boolean allowLongPressSupport() {

}

@Override public void onPlaybackError(MediaPlayer mp, int what, int extra) {

@Override public boolean onPlaybackError(MediaPlayer mp, int what, int extra) {
return true; // don't want to see the annoying dialog
}

@Override public void onPlaybackInfo(MediaPlayer mp, int what, int extra) {
Expand Down