Better error handling on iOS
This commit is contained in:
parent
ebc8584b97
commit
37fe2c865e
|
@ -141,11 +141,6 @@
|
||||||
} else {
|
} else {
|
||||||
result(FlutterMethodNotImplemented);
|
result(FlutterMethodNotImplemented);
|
||||||
}
|
}
|
||||||
// TODO
|
|
||||||
/* } catch (Exception e) { */
|
|
||||||
/* e.printStackTrace(); */
|
|
||||||
/* result.error("Error", null, null); */
|
|
||||||
/* } */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Untested
|
// Untested
|
||||||
|
@ -467,7 +462,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)load:(NSDictionary *)source result:(FlutterResult)result {
|
- (void)load:(NSDictionary *)source result:(FlutterResult)result {
|
||||||
// TODO: error if already connecting
|
if (_state == connecting) {
|
||||||
|
[self abortExistingConnection];
|
||||||
|
_playing = NO;
|
||||||
|
[_player pause];
|
||||||
|
} else if (_state == playing) {
|
||||||
|
_playing = NO;
|
||||||
|
[_player pause];
|
||||||
|
}
|
||||||
_connectionResult = result;
|
_connectionResult = result;
|
||||||
_index = 0;
|
_index = 0;
|
||||||
[self updatePosition];
|
[self updatePosition];
|
||||||
|
@ -671,13 +673,7 @@
|
||||||
}
|
}
|
||||||
case AVPlayerItemStatusFailed: {
|
case AVPlayerItemStatusFailed: {
|
||||||
NSLog(@"AVPlayerItemStatusFailed");
|
NSLog(@"AVPlayerItemStatusFailed");
|
||||||
if (playerItem != _player.currentItem) return;
|
[self sendErrorForItem:playerItem];
|
||||||
if (_connectionResult) {
|
|
||||||
_connectionResult([FlutterError errorWithCode:[NSString stringWithFormat:@"%d", _player.currentItem.error]
|
|
||||||
message:_player.currentItem.error.localizedDescription
|
|
||||||
details:nil]);
|
|
||||||
_connectionResult = nil;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AVPlayerItemStatusUnknown:
|
case AVPlayerItemStatusUnknown:
|
||||||
|
@ -777,6 +773,31 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)sendErrorForItem:(IndexedPlayerItem *)playerItem {
|
||||||
|
FlutterError *flutterError = [FlutterError errorWithCode:[NSString stringWithFormat:@"%d", playerItem.error]
|
||||||
|
message:playerItem.error.localizedDescription
|
||||||
|
details:nil];
|
||||||
|
[self sendError:flutterError playerItem:playerItem];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sendError:(FlutterError *)flutterError playerItem:(IndexedPlayerItem *)playerItem {
|
||||||
|
if (_connectionResult && playerItem == _player.currentItem) {
|
||||||
|
_connectionResult(flutterError);
|
||||||
|
_connectionResult = nil;
|
||||||
|
}
|
||||||
|
if (_eventSink) {
|
||||||
|
// Broadcast all errors even if they aren't on the current item.
|
||||||
|
_eventSink(flutterError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)abortExistingConnection {
|
||||||
|
FlutterError *flutterError = [FlutterError errorWithCode:@"abort"
|
||||||
|
message:@"Connection aborted"
|
||||||
|
details:nil];
|
||||||
|
[self sendError:flutterError playerItem:nil];
|
||||||
|
}
|
||||||
|
|
||||||
- (int)indexForItem:(IndexedPlayerItem *)playerItem {
|
- (int)indexForItem:(IndexedPlayerItem *)playerItem {
|
||||||
for (int i = 0; i < _indexedAudioSources.count; i++) {
|
for (int i = 0; i < _indexedAudioSources.count; i++) {
|
||||||
if (_indexedAudioSources[i].playerItem == playerItem) {
|
if (_indexedAudioSources[i].playerItem == playerItem) {
|
||||||
|
|
|
@ -29,33 +29,12 @@ class _MyAppState extends State<MyApp> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
//LoopingAudioSource(
|
|
||||||
// count: 2,
|
|
||||||
// child: AudioSource.uri(
|
|
||||||
// Uri.parse(
|
|
||||||
// "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3"),
|
|
||||||
// tag: AudioMetadata(
|
|
||||||
// album: "Science Friday",
|
|
||||||
// title: "A Salute To Head-Scratching Science (full)",
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
//),
|
|
||||||
//ClippingAudioSource(
|
|
||||||
// start: Duration(seconds: 60),
|
|
||||||
// end: Duration(seconds: 65),
|
|
||||||
// child: AudioSource.uri(Uri.parse(
|
|
||||||
// "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3")),
|
|
||||||
// tag: AudioMetadata(
|
|
||||||
// album: "Science Friday",
|
|
||||||
// title: "A Salute To Head-Scratching Science (5 seconds)",
|
|
||||||
// ),
|
|
||||||
//),
|
|
||||||
AudioSource.uri(
|
AudioSource.uri(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
"https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3"),
|
"https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3"),
|
||||||
tag: AudioMetadata(
|
tag: AudioMetadata(
|
||||||
album: "Science Friday",
|
album: "Science Friday",
|
||||||
title: "A Salute To Head-Scratching Science (full)",
|
title: "A Salute To Head-Scratching Science",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
AudioSource.uri(
|
AudioSource.uri(
|
||||||
|
@ -84,7 +63,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
try {
|
try {
|
||||||
await _player.load(_playlist);
|
await _player.load(_playlist);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// catch audio error ex: 404 url, wrong url ...
|
// catch load errors: 404 url, wrong url ...
|
||||||
print("$e");
|
print("$e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue