Exoplayer exceptions (#76)
* exoplayer exceptions back to flutter * fix git ignore * fix dispose player * pump exoplayer exceptions * readme * code reformat * code reformat - with tabs * re-reformat code
This commit is contained in:
parent
e02f59cd31
commit
5147a52397
12 changed files with 133 additions and 122 deletions
|
@ -1,7 +1,9 @@
|
|||
package com.ryanheise.just_audio;
|
||||
|
||||
import android.os.Handler;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
|
@ -15,6 +17,8 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
|||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
import io.flutter.Log;
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
import io.flutter.plugin.common.EventChannel.EventSink;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
|
@ -22,16 +26,21 @@ import io.flutter.plugin.common.MethodChannel;
|
|||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
import io.flutter.plugin.common.PluginRegistry.Registrar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AudioPlayer implements MethodCallHandler, Player.EventListener {
|
||||
static final String TAG = "AudioPlayer";
|
||||
|
||||
private final Registrar registrar;
|
||||
private final Context context;
|
||||
private final MethodChannel methodChannel;
|
||||
|
@ -141,6 +150,27 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerError(ExoPlaybackException error) {
|
||||
switch (error.type) {
|
||||
case ExoPlaybackException.TYPE_SOURCE:
|
||||
Log.e(TAG, "TYPE_SOURCE: " + error.getSourceException().getMessage());
|
||||
break;
|
||||
|
||||
case ExoPlaybackException.TYPE_RENDERER:
|
||||
Log.e(TAG, "TYPE_RENDERER: " + error.getRendererException().getMessage());
|
||||
break;
|
||||
|
||||
case ExoPlaybackException.TYPE_UNEXPECTED:
|
||||
Log.e(TAG, "TYPE_UNEXPECTED: " + error.getUnexpectedException().getMessage());
|
||||
break;
|
||||
|
||||
default:
|
||||
Log.e(TAG, "default: " + error.getUnexpectedException().getMessage());
|
||||
}
|
||||
this.setError(String.valueOf(error.type), error.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSeekProcessed() {
|
||||
if (seekResult != null) {
|
||||
|
@ -246,6 +276,13 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener {
|
|||
}
|
||||
}
|
||||
|
||||
private void setError(String errorCode, String errorMsg) {
|
||||
if (prepareResult != null) {
|
||||
prepareResult.error(errorCode, errorMsg, null);
|
||||
prepareResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void transition(final PlaybackState newState) {
|
||||
final PlaybackState oldState = state;
|
||||
state = newState;
|
||||
|
@ -261,7 +298,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener {
|
|||
DataSource.Factory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
|
||||
userAgent,
|
||||
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
|
||||
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
|
||||
true
|
||||
);
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, httpDataSourceFactory);
|
||||
|
@ -400,4 +437,4 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener {
|
|||
connecting,
|
||||
completed
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue