Last active
December 10, 2015 20:08
-
-
Save artanisdesign/4485678 to your computer and use it in GitHub Desktop.
Small hack for Titanium AudioPlayer to handle stream errors!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//.. | |
//AudioStreamer/AudioStreamerCUR.m | |
// | |
// failWithErrorCode: | |
// | |
// Sets the playback state to failed and logs the error. | |
// | |
// Parameters: | |
// anErrorCode - the error condition | |
// | |
- (void)failWithErrorCode:(TI_AudioStreamerErrorCode)anErrorCode | |
{ | |
@synchronized(self) | |
{ | |
if (errorCode != AS_NO_ERROR) | |
{ | |
// Only set the error once. | |
return; | |
} | |
errorCode = anErrorCode; | |
if (err) | |
{ | |
char *errChars = (char *)&err; | |
NSLog(@"%@ err: %c%c%c%c %d\n", | |
[AudioStreamer stringForErrorCode:anErrorCode], | |
errChars[3], errChars[2], errChars[1], errChars[0], | |
(int)err); | |
} | |
else | |
{ | |
NSLog(@"%@", [AudioStreamer stringForErrorCode:anErrorCode]); | |
//********// | |
//not a nice solution, but i needed it urgent. so, special error code 99 if stream error happens | |
self.state = 99; | |
stopReason = AS_STOPPING_ERROR; | |
AudioQueueStop(audioQueue, true); | |
} | |
if (state == AS_PLAYING || | |
state == AS_PAUSED || | |
state == AS_BUFFERING) | |
{ | |
self.state = AS_STOPPING; | |
stopReason = AS_STOPPING_ERROR; | |
AudioQueueStop(audioQueue, true); | |
} | |
///you can comment out the alert window if you dont need it. | |
[self presentAlertWithTitle:NSLocalizedStringFromTable(@"File Error", @"Errors", nil) | |
message:NSLocalizedStringFromTable(@"Unable to configure network read stream.", @"Errors", nil)]; | |
} | |
} | |
//.... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//.. | |
//TiMediaAudioPlayerProxy.m | |
-(NSString*)stateToString:(int)state | |
{ | |
switch(state) | |
{ | |
case AS_INITIALIZED: | |
return @"initialized"; | |
case AS_STARTING_FILE_THREAD: | |
return @"starting"; | |
case AS_WAITING_FOR_DATA: | |
return @"waiting_for_data"; | |
case AS_WAITING_FOR_QUEUE_TO_START: | |
return @"waiting_for_queue"; | |
case AS_PLAYING: | |
return @"playing"; | |
case AS_BUFFERING: | |
return @"buffering"; | |
case AS_STOPPING: | |
return @"stopping"; | |
case AS_STOPPED: | |
return @"stopped"; | |
case AS_PAUSED: | |
return @"paused"; | |
/*my unique error code*/ | |
case 99: | |
return @"error"; | |
} | |
return @"unknown"; | |
} | |
//.. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment