[TIMOB-15468] iOS: Titanium.Media.AudioPlayer needs an error event
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-06-01T21:46:09.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | TiAPI |
Labels | AudioPlayer, TSP, error, event |
Reporter | kosso |
Assignee | Eric Merriman |
Created | 2013-10-01T15:05:27.000+0000 |
Updated | 2017-03-21T21:01:46.000+0000 |
Description
Titanium.Media.AudioPlayer really needs a proper error event. 'Change' and 'progress' aren't enough.
Currently, if a stream is broken, or (as is often the case) has the wrong buffer size set (as can be demonstrated in the KitchenSink remote streaming example) we only forced the same alert "Unable to configure network read stream".
This error info isn't very useful. Debug logs shows more info logged by AudioStreamer.m which provides more info eg : "Audio packets are larger than kAQBufSize."
Still no activity on this. If a stream fails to start() the "File Error: Unable to configure network read stream" alert pops up and there's no way get rid of that, or catch anything to provide a better message/retry.
This looks to be a simple fix on iOS. The AudioStreamerCUR.m file has a failWithErrorCode method which is throwing up the error alert. This just needs to be fired back in an error event.
In fact, there is still a silly amount of disparity between iOS and Android, when it comes to the AudioPlayer. State codes differ. iOS has no setTime() ability. Android seems to only fire the 'complete' event. etc. I'm sure these were previously addressed a while ago.
It would also be very useful to detect when the audioPlayer (for example, playing a radio stream in the background) is 'interrupted' by things like an Alarm (or any other audio notification), audio in another app 'stealing' the session, Siri, etc. - Currently, after the audio is interrupted, it does not recover afterwards. I have used a module which uses CoreTelephony to detect when the stream is interrupted (app paused) by a phone call and have been able to stop/resume my stream when that occurs.
More on this: I see that the original AudioStreamer implementation by Steve Tramer was a modification of some popular code by Matt Gallagher. Recently, while looking for a solution to obtaining now-playing metadata from ShoutCast stream, I've come across another modified version of the AudioStreamer classes which will detect and read the 'Icy-Metadata' if present. It would be great to add this patch to our AudioPlayer if possible. https://code.google.com/p/audiostreamer-meta/ This solution is based on an article here, which explains how metadata is streamed by ShoutCast. http://www.smackfu.com/stuff/programming/shoutcast.html Thanks.
update : There is a much, much more recent fork of the AudioStreamer classes here, which has built-in support for Shoutcast metadata, ID3 tags, seeking and also playlists (Ti devs often use the Media.videoPlayer for playlists .m3u etc.) https://github.com/alexcrichton/AudioStreamer/tree/master/AudioStreamer Please can we have a solution based around this? It would be a huge, huge improvement to the very old methods we currently have.
If someone is willing/able to contribute a solution to this, we would be glad to assist.
If I knew how to do it, I would (I'm an extreme novice when it comes to Objective-C) ;) I've done the research bit ;)
Hi, I seen the status of this update a few times recently. Is there a rough ETA of when this might be fixed? I have a radio station app to get updated which really needs this as soon as possible. Thanks.
PR here: https://github.com/appcelerator/titanium_mobile/pull/6879 Added iOS error event, as well as documented together with Android. Also removed alert dialog that shows generic error. Users are now required to process the returned error event.
Sample Code (same as documentation, but added error event listener)
Steps to test
1. Run sample app while online 2. *Start / Stop Streaming* 3. While music is playing, go offlineExpected result
the error event should be caught, and console prints out error description+1 Thanks! I'll try this out.
Hi, This worked for me. Also including Pedro's extra fixes since your PR. Thank you! BUT one more thing which just occurred to me also, is the fact that the iOS version of AudioPlayer does not have a 'complete' event. Android does have this event. The 'complete' event should fire when the player reaches the end of a file. Could this also be added? For the sake of parity. Thank you.
Closing ticket as fixed.