[TIMOB-24909] iOS: Move Ti.Media.AudioPlayer to AVPlayer internally, remove external library-dependency
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-07-28T17:39:38.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 7.5.0 |
Components | iOS |
Labels | audioplayer, demo_app |
Reporter | Hans Knöchel |
Assignee | Hans Knöchel |
Created | 2017-06-29T19:44:04.000+0000 |
Updated | 2018-10-10T12:48:38.000+0000 |
Description
Right now, we use the (outdated and unmaintained) iOS library "AudioStreamer" for our Ti.Media.AudioPlayer API. Nowadays, modern iOS API's help us, especially the
AVPlayer
inside AVFoundation
. This will also resolve a number of tickets with a high numbers of watchers:
- TIMOB-19519
- TIMOB-3375
The time-frame should be around SDK release 7.1.0 / 7.2.0 with 100 % backwards-compatibility.
See the [Ti.Media.AudioPlayer](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Media.AudioPlayer) docs for more infos.
Attachments
File | Date | Size |
---|---|---|
sample.mp3 | 2018-01-15T08:28:03.000+0000 | 37596 |
I must admit I gave up on this and implemented by own player in Hyperloop using AVPlayer. It works quite well but for not being able to implement any kind of listeners to get feedback from the the player. AVPlayer has no delegate and Apple expect us to use KVO, but nobody has been able to tell me how to do that it Hyperloop! I ended up using a 3 second setInterval to poll the player's 'timeControlStatus' property. So a new version of Ti.Media.AudioPlayer using AVPlayer with player monitoring would be good!
PR: https://github.com/appcelerator/titanium_mobile/pull/9732 Test-Cases: *#1: Remote file, some events*
*#2: Real time radio streams*:
For the watchers of this ticket: Now is the chance to propose API's that could be added with AVPlayer. Let me know if there are specific functionalities being useful for the general developer.
Thanks for reaching out Hans. For me, as I am using AudioPlayer for radio streaming, being able to picked timedMetadata for the playing artist & title is important. In fact so much so that I have written my own module using AVPlayer (which I am still testing). But as you are way ahead of me on the Objective-C skills I am happy to use the updated official Appcelerator AudioPlayer API when it is released. Have you any rough idea of when SKD 7.2.0 is likely to happen? Cheers.
Thanks [~patrickmounteney]. The
timedMetadata
API is huge. What API's from there are relevant? Only the value of each item in the array? *EDIT*: Looks like key, keySpace, value & extraAttributes are pretty powerful already (some debug output from Xcode):Mapped into a Titanium event:
Using a new
metadata
event. Timeline for 7.2.0 is over the next few months, but you can use the pull request and patch your 7.x SDK today.All I am doing is sticking a listener on the playerItem as per:
and picking it up in 'observeValueForKeyPath' like this:
But I have not worked with Objective-C much and I expect there is a better way to do it. Sorry - how does one get code to appear as you have it in a nice box?
Use the ````
tags for that (or select from the "+" at the right). I've just pushed [this commit](https://github.com/appcelerator/titanium_mobile/pull/9732/commits/94b748ccdfbdedae943b94616bdeac9b78acbe76) that adds the
metadata` event as part of the main [pull request](https://github.com/appcelerator/titanium_mobile/pull/9732). Try it out!That's great Hans. I'll have a look when I have a moment.
Another useful addition would be to make Ti.Media.AudioPlayer work with the iOS MPNowPlayingInfoCenter and the lockscreen. Something I have been unable to do in my little module. There is an existing module for this (by Foddy), but I don't think it is able to update in the background.
[~patrickmounteney] that would be the
Ti.Media.MusicPlayer
, not the audioPlayer.Well, in my DIY module I am using MPNowPlayingInfoCenter as per:
The the title and artist are obtained from AVPlayerItem's timedMetadata. And that does seem to update the lock screen whilst the player is in the background.
[~patrickmounteney] The initial implementation has been finished already, so new features won't slip into the core change of the API at this time. But you could use Hyperloop easily for this, even today already:
Eventually, the JavaScript
Object
object needs to be mapped to a nativeNSDictionary
, but it could even work like this already.*Closing ticket.* Verified improvement on SDK Version
7.5.0.v20181008124804
. *FR Passed (Test Steps)*Created a new Titanium application
Added the first test case mentioned above in to the
app.js
Ran the program
Started stream and was able to hear sound
Pressed
stop
and sound was stoppedAlso able to pause and resume using the
pause/resume stream
buttonPressed
Change URL
URL was changed and local file started to play
Backgrounded the application and sound was still playing
Above steps were also used for the second test case (Real time audio streams)
*Test Environment*