dimitris-c / audiostreaming Goto Github PK
View Code? Open in Web Editor NEWAn AudioPlayer/Streaming library for iOS written in Swift using AVAudioEngine.
License: MIT License
An AudioPlayer/Streaming library for iOS written in Swift using AVAudioEngine.
License: MIT License
This happened sometimes.
I'm playing bunch of episodes. it crashes sometimes if we call recreatePlayer before playing next.
self.player.stop()
self.recreatePlayer()
self.player.play(url: url)
bug demo repo:
https://github.com/newbdez33/AudioStreamingBug/tree/render-crash
Tested main branch in iOS 14.2 Simulator and iPhone 7. (Xcode 12.2 and Xcode 12.3)
Hello!
It looks like the last tagged version on Cocoapods is 0.9.0, given we're now on 1.2.x would it be possible to update it?
Thank you!
Hello!
how to play files MPMediaItem witch assetURL ?
for example:
assetURL = Optional(ipod-library://item/item.m4a?id=6247563662587856568)
the framework tries to look for something on the network.
the file is not played.
When instantiating AudioPlayer() , the currently activated AVAudioSession is deactivated. So, when starting the app, it stops the playback from other apps. This is not how apps like Apple Music or Podcasts behave.
Please have AudioPlayer() not close the current Audio-Sessions during initialization, so that one can instead activate it before calling the play() command.
Hi,
What about an audio plot graph?
Is it possible? It would be extra!
Cheers,
Hi! I-m trying this lib, using swift 5, xcode 12.5.1
@IBAction func onPlay(_ sender: Any) {
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
let player = AudioPlayer()
player.play(url: URL(string: "https://www.kozco.com/tech/piano2-CoolEdit.mp3")!)
}
this not works. I can't hear anything.
Do I need some permission. or something like that?
Also I have this in my info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
I received this in the log
[audio.streaming.generic] audio file stream not opened
Hello,
The project promises to be awesome! Bravo!
This is not an issue as I have not tested yet in one of my projects, but a question.
The main question is:
How to achieve this (from streamingKit), as your framework is not yet documented:
audioPlayer.appendFrameFilter(withName: "CustomEQFilter") { (channelsPerFrame, bytesPerFrame, frameCount, frames) in
// Here I update my VU-Meter class for display.
}
Thanks,
It is almost 100% reproduced if there are many queued mp3 urls in queue.
I created a repo for this issue.
https://github.com/newbdez33/AudioStreamingBug
The basic code is queue all playlist items to player.queue()
for item in playlist {
if let url = URL(string: item) {
print("queue:\(url)")
player.queue(url: url)
}
}
Sometimes it plays 2 or 3 items then stoped.
Tested main branch in iOS 14.2 Simulator and iPhone 7. (Xcode 12.2 and Xcode 12.3)
Hi, first off, I wanted to applaud you on this project ... this is a really awesome concept that would be useful to many !
One suggestion - I know that you have provided an easy hook to attach audio nodes, but it would be great if you could include a built-in equalizer that is easy for clients to manipulate, so that clients don't have to deal with the complexity of configuring an AVAudioUnitEQ node themselves.
You could provide an ISO standard 10-band EQ out of the box, which would be the most common type of EQ.
Ideally, clients would use it as follows:
let player = AudioPlayer()
// Activate the EQ.
player.eqBypass = false
// Set global gain to +5.0 dB
player.eqGlobalGain = 5.0
// Set the gain of the 3rd band to +7 dB.
player.setEQBand(2, to: 7.0)
// Get the gain of the 4th band.
let fourthBandGain = player.getEQBand(3)
// Set all EQ band gains.
player.eqBands = [0.0, 2.5, 5.5, 7.5, 5.0, ...]
// Get all EQ band gains.
print("EQ bands are currently set to: \(player.eqBands)")
I can't play local file “bensound-jazzyfrenchy.m4a” with v1.2.0
We noticed this issue on our application but also in the example in GitHub. Trying to play "Swift by Sundell" podcast and then again "Swift by Sundell" the memory used is constantly increasing. It seems that the allocated memory (200MB for this audio item) is not released. This behaviour does not affect live streaming audio like radio stations.
streaming play "https://p3.openlanguage.com/obj/ez-data/16469702308217854cf0b0f.mp3"
can not slide progress bar to seek
As the title says, it seems like the audio player ignores system events like disconnecting headphones/CarPlay and keeps playing when it should stop, and if a phone call is received or made while audio is playing, playback doesn't resume after the call is done.
Am i missing something? Is this intended behavior?
Thanks @dimitris-c for this great project.
When you start playing for a while(example project), it will suddenly speed up extremely fast.
Then it will loop a small piece of audio (a few seconds).
You may try to play a full podcast audio, It happens 100% chance.
I'm using iOS 14.2, Xcode 12.2
Hey!
First of all, thank you for this neat library. It drives my SwiftUI radio app. The audio streaming and ICY metadata parsing works perfectly well.
There is just one thing: Is it possible to have the player.volume setting of the AudioStreaming engine linked to the iOS volume?
Hello!
seek function is unstable
crashes very often
2023-04-16 14:09:40.989409+0300 uPlayer[33449:10807909] [audio.streaming.generic] seek failed (
"The amount of data provided to the parser was insufficient to produce any result."
)
2023-04-16 14:09:40.989562+0300 uPlayer[33449:10807909] [SwiftUI] Invalid frame dimension (negative or non-finite).
Hi,
I'm just exploring this great framework for some audio streaming and noticed that the audio does not play after I have manually scrolled the progress handle to skip half the audio. It stays paused in the example app.
Hope there's a fix for this :)
Thanks,
Usman
Both on the example app and on my own app if I play audio from a stream iOS doesn't show anything playing on the lockscreen or in Control Center.
Is this intended behaviour?
would it take a lot of work to make this compatible with macOS?
let player = AudioPlayer()
player.play(url: URL(string: "https://your-remote-url/to/audio-file.mp3")!)
player.queue(urls: [
URL(string: "https://your-remote-url/to/audio-file.mp3")!,
URL(string: "https://your-remote-url/to/audio-file.mp3")!
])
the
sourceQueue.async { [weak self] in
guard let self = self else { return }
self.processSource()
}
from the play() method will call the processSource() which will clear the queue after it was populated.
My assumption being that the first lines of code are correct and the queueing of the URLs should be called after the play method which starts the audio engine if needed.
Hello and thank you for your great job.
I was wandering if your library can be used to play a constant audio stream coming from a connected USB device, an FM Radio with 2 channels.
I' trying to "update" an old application I made more than 10 years ago, ie developed on Mac which I know it is not supported (hoping yet) by your lib, but I'm stack in the old way of playback the stream coming from the device which after sometimes get corrupted or crashes the app. Even if it is compiling OK in Xcode 15.
I did use the tools and frameworks available at that time (but mostly swift code beside just the streaming written in C++...)
Thanx
Thanks for this project it looks really promising! I want to use this for my audio playback application, but while it is possible to enqueue tracks it is not possible, at least using the public api, to dequeue them. Making this part of the public api would be great
How to use it to stream system audio, or use it to receive system audio streams directly?
how can get downloaded buffer to display on slider
Hey! Thanks for the amazing library.
I'm observing the changes in the audio player using:
.onChange(of: player.state, { oldValue, newValue in
print(oldValue, newValue)
})
I'd like to bind back the new state to a variable, specifically when the audio starts playing, logically the buffering status should go away.
While everything works as expected, the buffering state should update to something like "playing", which currently does not get updated.
Here's the example log from the console:
Please correct me if I'm doing something wrong here. Again, thanks!
I'm using this library for a radio streaming app and a lot of links are m3u audio streams that I can open no problem in Safari on iOS, but aren't compatible with this library.
Any chance for this feature being added?
Here's an example m3u link that works in Safari on iOS: link
Hey guys!
I have an issue, where audio is only playing while the Silent Mode is off on iPhone.
Is there any way to fix this?
Thank you for your answers.
First of all - thank you so much for this library! It's really helpful in the project I'm working at right now.
I noticed that the API for AudioPlayer
has separate play(url:)
and seek(to:)
methods. I would love to be able to merge these two and ask the AudioPlayer
to start playing back the item at a specific location. (i.e. play(url:at:)
)
When I tried to simulate this behavior by calling play
and seek
in a sequential order, the seek command seemed to be ignored, unless I delay it slightly via DispatchQueue
. I assume it's due to the time it takes for the item to enter audioPlayingEntry
.
How would you go about implementing playback at a specific time interval? Happy to look into this and try to make a PR out of it, but would appreciate some guidance! :)
Is there any way to play local music from libray? this audio file's url looks like:
ipod-library://item/item.mp3?id=626678501701109259\
But it shows this error:
Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSErrorFailingURLStringKey=ipod-library://item/item.mp3?id=626678501701109259, NSErrorFailingURLKey=ipod-library://item/item.mp3?id=626678501701109259, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask .<45>"
Can anyone help?
let filePath1 = "/var....myFile1.m4a" // local audio file URL with m4a extension
let filePath2 = "/var....myFile2.m4a" // local audio file URL with m4a extension
let player = AudioPlayer() // Player initialisation
@IBAction func buttonOneClick(_ sender: Any) {
player.play(url: URL(fileURLWithPath: filePath1))
}
@IBAction func buttonTwoClick(_ sender: Any) {
player.play(url: URL(fileURLWithPath: filePath2))
}
Scenario : When I played on buttonOneClick then player working fine and after completing first audio then click on buttonTwoClick then getting below error.
Xcode console throwing this error while playing second music :
Error: (
"Couldn't parse the bytes from the stream. Status: It is not possible to produce output packets because the\nstreamed audio file's packet table or other defining information is not present or appears after the audio data."
)
We want to play m4a file but from two different button with different audio file having m4a format.
Could you please assist here?
Originally posted by @appDeveloper7 in #41 (comment)
This podcast:
https://pdst.fm/e/chtbl.com/track/95538/traffic.megaphone.fm/ADL7076246752.mp3
Playing it is fine, but when you do "seek", the player lost duration(duration == 0).
And it can not perform seek anymore( will cause crash ).
There are also other podcast have same issue.
I'm looking into the issue, but unless you've already addressed it :)
I got this error while playing an audio. This audio recorded from samsung mobile.
"Couldn't parse the bytes from the stream. Status: The file is malformed, not a valid instance of an audio file of its type, or not recognized as an audio file."
Note: But this same audio is playing well in avplayer and safari browser also.
let filePath1 = "/var...."
let filePath2 = "/var...."
@IBAction func buttonOneClick(_ sender: Any) {
player.play(url: URL(fileURLWithPath: filePath1))
}
@IBAction func buttonTwoClick(_ sender: Any) {
player.play(url: URL(fileURLWithPath: filePath2))
}
Xcode console throwing this error while playing second music :
Error: (
"Couldn't parse the bytes from the stream. Status: It is not possible to produce output packets because the\nstreamed audio file's packet table or other defining information is not present or appears after the audio data."
)
After the playback of the remote file ends, in
func audioPlayerDidFinishPlaying(player: AudioStreaming.AudioPlayer,
entryId: AudioStreaming.AudioEntryId,
stopReason: AudioStreaming.AudioPlayerStopReason,
progress: Double,
duration: Double)
i get
stopReason == .none
not .eof
i drilled down why this happens and its because the atomic writing block for stopReason is executed after the delegate callback, despite the atomic operation is requested earlier
iOS16
Hi there, there seems to be an issue with local audio playback when attempting to seek to 0 seconds. When doing this the audio starts playing from ~4 seconds into the track. This does not affect streamed audio in the same way for some reason.
You can recreate this by:
Hi,
May I ask you why the size of the buffer received in the call back of FilterEntry is so large (mDataByteSyze)? (17640 instead of 2048 for StreamingKit). This decreases the performance (speed) of the frequency analyzer I am using.
So the refresh of my VU-Meter view is too slow.
Maybe I'm missing something?
Thanks.
HI, how much work would it take to add an @published value to update the progress as the track plays on.
Or does this currently exist?
Hi, I am currently evaluating different audio libraries to add gapless playback to my Ampache/Subsonic App: Amperfy
I integrated AudioStream and I am able to play songs with it.
I am still noticing a small gap between songs.
The engine is used with default configuration. The first song is played via player.play(url: url)
. 10 seconds before the currently playing song is finished I queue the next song via player.queue(url: url)
.
Do I need to adjust/configure something get a true gapless playback?
When internet connection is unstable, the sound of the stream isn’t available. Looks like this player hasn’t a buffer. For example, the avplayer plays stream for 10 seconds if the internet connection has been lost
Adding pod 'AudioStreaming'
to the Podfile does not work because AudioStreaming does not exist on Cocoapod.
Am I missing something?
I have found crash on Crashlytics that says audioPlayerDidFinishPlaying(player:entryId:stopReason:progress:duration:). The issue occurs sometime. Can you help me how to fix this issue.
First of all, thank you for this library. It really did help me starting playing audios faster than using Apple's out-of-the-box solution.
But, I've just noticed an issue, not sure if that's something on my side. When an audio is paused, then another audio is set to be played, the previous audio starts playing for a faction of a second then the new audio starts playing.
I was in a hurry, so after some trial and error, I figured that stopping the player and changing the play(url: URL, headers: [String: String]) method in AudioPlayer to the following did the trick , but that's not a perfect solution for sure.
public func play(url: URL, headers: [String: String]) {
let audioEntry = entryProvider.provideAudioEntry(url: url, headers: headers)
audioEntry.delegate = self
checkRenderWaitingAndNotifyIfNeeded()
sourceQueue.async { [weak self] in
guard let self = self else { return }
clearQueue()
entriesQueue.enqueue(item: audioEntry, type: .upcoming)
playerContext.setInternalState(to: .pendingNext)
do {
try self.startEngineIfNeeded()
} catch {
self.raiseUnexpected(error: .audioSystemError(.engineFailure))
}
self.processSource()
}
}
Thank you again and I'd appreciate your feedback to this issue.
https://mcdn.podbean.com/mf/web/khh8azvsc8bedf9a/Boomers_Know_Stuff_Part_1_2378b1ju.m4a
can't play this file with v1.2.0
Would love to see the feature where I can loop the given audio indefinitely. Most audio players offers this feature, including AVPlayer
, AVAudioPlayer
from Apple, and ExoPlayer
from Google.
Hey, thanks for the great library!
I have a use case where I need to load the audio file, for example to get the duration displaying but not autoplay. I was digging around the code but couldn't see any obvious way to do this apart from play then instantly pause?
Hello, I found a issue when using the framework.
When I want to use audioPlayerDidStartPlaying(player:with:) in AudioPlayerDelegate to get the currently playing audio, I can't get the correct entry.
Current playing entry is nextEntry,
I don't know whether it was deliberately done. If so, how can I operate it better?
Look forward to your reply.
We noticed this behavior using the 0.5.0 version. The scenario is that the Player is playing a radio stream and the device is getting a phone call. Using the AVAudioSession.interruptionNotification we are able to pause the Player. When the call ends we resume the Player. When the call's duration exceeds 60 secs the Player resumes playing for a couple of seconds and then falls in a "buffering" state forever.
Calls with a duration of fewer than 60 secs are handled properly and the player resumes playing as expected.
Do you think this is normal behaviour or do we need to handle in a different way the above situation?
Hello,
I want my app to be able to play multiple audio URLs simultaneously. Could you please provide guidance or hints on how I can achieve this? Any assistance would be greatly appreciated.
Thank you!
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.