tschob / audioplayermanager Goto Github PK
View Code? Open in Web Editor NEW⚠️ No longer maintained ⚠️ Small Swift Wrapper and Queue-Manager around AVPlayer which let you play MediaPlayer items and stream songs from URLs.
License: MIT License
⚠️ No longer maintained ⚠️ Small Swift Wrapper and Queue-Manager around AVPlayer which let you play MediaPlayer items and stream songs from URLs.
License: MIT License
My app plays video and audio.
I start fullscreen videos like this:
func startFullscreenVideo(videoURL:URL) {
let player = AVPlayer(url: videoURL)
let controller = AVPlayerViewController()
controller.player = player
present(controller, animated: true) {
player.play()
}
}
and the Audio with your library.
Problem: After playing Audio, then playing a Video, and then playing Audio again the App stops to show a Music Player in Background/Lock Screen/Control Center (https://i.stack.imgur.com/zXRw2.jpg this one starts missing).
This is a weird bug and I hope you can help me.
there is no way to set the volume or get access to avplayer.
AudioPlayerManager.shared.play(urlString: songUrlString)
Playing this code from background does not work either.
Hello! Wie geht es dit? this is a really awesome repo by the way!
I have noticed a problem when trying my app that uses your repo which is that the seek bar is not shown in control center. Please note that i am not sure if the problem is only in my use case or the loadDuration func is bugged. The problem was in the function "updateNowPlayingInfoPlaybackDuration" of AudioTrack.swift it returned nil duration and i was able to solve it by changing it to
open func updateNowPlayingInfoPlaybackDuration() {
self.playerItem?.asset.loadDuration(completion: { [weak self] (duration: NSNumber?) in
if duration != nil {
self?.nowPlayingInfo?[MPMediaItemPropertyPlaybackDuration] = duration
} else {
if let durationShit = self?.playerItem?.asset.duration, durationShit != CMTime.indefinite {
self?.nowPlayingInfo?[MPMediaItemPropertyPlaybackDuration] = NSNumber(value: CMTimeGetSeconds(durationShit))
print("did set duration = \(NSNumber(value: CMTimeGetSeconds(durationShit)))")
}
}
})
}
Have a nice day.
Hi, Is there any way to set custom metadata like title and albumart while playing from url?
I'm learning swift and try to make a simple music player by using MPMediaQuery. But I find it hard to get currentItemIndex to update the UI with it's data(cover, title and so on). Without index , it's hard to achieve single circle mode or shuffle mode. Do u have a better way to make it ? Sorry for my poor English, looking forawrd to your reply.
Add support for building with Swift 4
I have successfully downloaded the audio and saved it to application documents directory. But can't find any method to play it.
hi,
after adding songs with AudioPlayerManager.shared.play(urlStrings: urls, at: index)
how can i play a song at an index without passing urls again ?
I am using the framework for playing URL with index.
whenever there is a change of track Main thread completely freezes.
[AudioPlayerManager].restartCurrentTrack()[397]: restartCurrentTrack is debug console print at the time of freeze
The bahvior can be already implemented with the following snippet, but a little bit of syntx suggar would be nice. Improves #20
guard let _currentTimeInSeconds = AudioPlayerManager.shared.currentTrack?.currentTimeInSeconds() else {
return
}
var newTimeInSeconds = _currentTimeInSeconds - 10
if (newTimeInSeconds < 0) {
newTimeInSeconds = 0
}
let time = CMTimeMake(Int64(newTimeInSeconds), 1)
AudioPlayerManager.shared.seek(toTime: time)
Altough the problem from #20 can't be fixed inside the library the duration value shouldn't be 0
if there is no duration but should be nil
. Otherwise it's not clear whether the duration is really 0
or if there is none like in live streams.
line: self.nowPlayingInfo?[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(image: _image)
gives warning 'init(image:)' was deprecated in iOS 10.0
Hi,
Is it possible to get player state? Like Buffering, Error, Playing and Pause. I can get playing and pause by AudioPlayerManager.shared.isPlaying()
. But would like to know if there is build in function to get other states.
How do I get the current playback time from this library? I need to update the screen.
For eg: addPeriodicTimeObserver
I'm not sure if the documentation is lying to me, or the code is wrong.
AudioPlayerManager.swift v.1.2.3
/// Set this to true if the `AudioPlayerManager` log should be enabled. The default is `false`.
open static var verbose = true
Unable to get BPM, doing the following in viewDidLoad
let tempData = MPMediaQuery.songs().items ?? []
self.data = []
for mediaItem in tempData {
if (mediaItem.isCloudItem == false && mediaItem.assetURL != nil) {
self.data.append(mediaItem)
if (self.data.count >= 20) {
var bpm: Int? = mediaItem.value(forProperty: MPMediaItemPropertyBeatsPerMinute) as? Int
print(bpm)
break
}
}
}
Play doesn't work immediately on ios 10+. It works quite well below ios 10.
guard let url = URL(string: (self?.mMediaItem.media!)!) else { return }
let audioUrlTrack = AudioURLTrack(url: url)
AudioPlayerManager.shared.play(audioUrlTrack!)
Hi !
I want to know how to support airplay sharing ?
How how to update playing speed ? x1.25, x1.5, x2.0 ect
Thanks
First of all thanks for this amazing library, it has been really helpful so far. I was trying find a way to set images from url as album artwork but could not find anything. Any help would be appreciated.
I was looking for a decently solid library to start streaming MP3s from and your wrapper around AVPlayer has been awesome and saved a lot of time so far.
I've noticed with iOS 10 devices, when streaming through AVPlayer, it tends to buffer and create a noticeable lag from the time "play" is commanded and when it actually starts playing audio.
Any thoughts on adding a check for iOS 10 in the open func play(updateNowPlayingInfo: Bool = false)
and then adding a playImmediately(atRate: 1.0)
in there?
Pause the song and click forward or rewind button then player is automatically playing the song.
After play sound from url it's stop automatically after few second (10-20) I used same url in example.
I'm getting this error when i run the code
player.setup()
player.play(url: URL(string: "url/media/podcast/z3f1fi18.mp3"))
Error at class: AudioTrack
method: updateNowPlayingInfoPlaybackDuration
open func updateNowPlayingInfoPlaybackDuration() {
if let _playerItem = self.playerItem {
let duration = NSNumber(value: Int(CMTimeGetSeconds(_playerItem.asset.duration)) as Int)
self.nowPlayingInfo?[MPMediaItemPropertyPlaybackDuration] = duration
any solution?
Hi,
does this library support play in background ?
the library works great with other mp3 links, however it does not play my link (from my server)
perhaps it is something that i need to do in my server, however if you can help me, it would be a lot appreciated
my link
http://projectm.e-rundev.ir/api/song/download/11.mp3
hi,
AudioPlayerManager.shared.play(urlStrings: urls, at: 0)
method actually blocks the UI,
how about doing it in background?
actually using this snippet this can be achieved for now, but I think it may be better if it was embedded in library
DispatchQueue.global().async {
DispatchQueue.main.async(execute: {
AudioPlayerManager.shared.play(urlStrings: urls, at: 0)
})
}
is it possible to cache remote files ?
perhaps using this project CachingPlayerItem
Sorry for creating issue here.
i want to use FolioReaderKit in my app, pod installed but i got an following error while opening book.
Assertion failure in -[MPSkipTrackCommand addTarget:action:], /Library/Caches/com.apple.xbs/Sources/MediaPlayer/MobileMusicPlayer-4017.700.3/SDK/MPRemoteCommand.m:134
2020-09-15 13:48:56.405087+0500 ShelfDemo[1743:367467]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported action method signature. Must return MPRemoteCommandHandlerStatus or take a completion handler as the second argument.
Could you please help me what is wrong my side ?
The AudioPlayerManager
class has two public functions that take a queue number/generation as a parameter.
open func prepend(_ audioTracks: [AudioTrack], toQueue generation: Int)
open func append(_ audioTracks: [AudioTrack], toQueue generation: Int)
Inside those two methods a test is made against the current generation or the operation fails. There is no way to determine what a valid value for that might be. The current generation for the manager is a private variable, and none of the methods ever returns the value of that variable.
This makes the prepend
and append
functions unusable.
There are two, three, enumerable ways to fix this. Here are a few.
to make the queueGeneration
variable public,
open var queueGeneration
plus: simple fix
minus: it doesn't provide whatever protection that check is trying to help in the first place, except to scrupulous programmers
plus: it still allows some provided functionality to programmers that want that check to occur
update every function that touches/changes the generation to return the new generation, the code that called the function that causes the new generation is the code that is allowed to modify the queue
this code that modifies the queue generation value includes:
private func clearQueue()
open func replace(with audioTracks: [AudioTrack], at startIndex: Int)
and indirectly, all other replace
and play
calls, as well as stop
add new, additional API for those interested in later calling prepend
or (more likely) append
, which provides the generation value they need
minus: this is at least 7 different calls currently
you could add two additional append/prepend functions that ignore the queue generation, this would allow the same bypass as "The Easy Way" but would not expose the internal value.
open func prepend(_ audioTracks: [AudioTrack])
open func append(_ audioTracks: [AudioTrack])
✅ The Easy Way
Hi! Very good job and i wonder is there any further update ?
Hi,
thanks for the great job
is there any way that I can add headers to the url(s) so I can satisfy some security protocols of the server ?
Hi,
is there any supported way to handle remote events ?
hi,
using following code, i'm not able to seek the song to my progress. it just restarts the song
AudioPlayerManager.shared.seek(toProgress: songSlider.value)
songslider.value returns a correct float
am i doing something wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.