Swift playing sound doesn't seem to work on my app - swift

Iv'e tried using the SwiftySound lib
but from some reason it didn't work, Iv'e also tried to play a sound using the AVFoundation but it doesn't seems to work neither (it's wether I get a nil on the url or it's simply doesn't work). the device is not muted and the speakers works fine, does anyone know what it might be?

Make sure you are adding your sound files to your project and also to your application target. It may be the case that, AVfoundation or SwiftySound not able to find your sound file. Also check out example project of SwiftySound.
pod try SwiftySound
Also check out other similar questions:- iOS Sound not playing in Swift

Related

Custom audio control for ios apps

We are creating an app using Swift on IOS that needs to use custom audio controls: a play button, a stop button, a current time/pos indicator, the duration and perhaps even a seek bar to play 1 audio file that is built into the application. My friend has worked hard on this project but so far was unable to find a solution. Is it possible using mediaplayer or is another api easier, possibly something similar to exoplayer for android apps.
Thanks.
In my opinion I would say that using AVFoundation would probably be easiest since it is built into swift you just have to do import AVFoundation and you would probably want to create an AVAudioPlayer to listen to the music. Also the API is pretty simple. If you need any help getting started I found this article on Mashable that shows how to play audio and how to control it with a custom play and pause button. https://medium.com/yay-its-erica/creating-a-music-player-app-in-swift-3-53809471f663. Also I found on Apple's documentation how to get the current time of the audio playing https://developer.apple.com/documentation/avfoundation/avaudioplayer/1387297-currenttime. I hope I was able to help and if you have anymore questions don't hesitate to ask!

How to loop an mp3 without gaps in monotouch?

I am wishing to seamlessly loop mp3's for an app written in MonoTouch using the AVAudioPlayer and cannot find any examples on how to achieve this. I have found a great library at http://gamua.com/blog/2012/05/gapless-mp3-audio-on-ios/ however it is written for objective c.
I wish for the audio to continue to play even when the device is locked and have played around with the AudioSession initilizer but failed to have this working also.
I am not able to find examples or libraries to assist in achieving results.
For queuing up songs without any spaces in between, make sure to use AVQueuePlayer, it allows you to pre-load songs. If you just want to loop the same song, just set NumberOfLoops to 0 on AVAudioPlayer and it will loop forever.
For playing audio in the background, you also need to declare UIBackgroundModes in your Info.plist. See this guy's article here. He's using Obj-C, but you should be able to port his code to MonoTouch.

AVAssetExportSession missing audio track when exporting on device

I run the export on the simulator and everything works great. I run it on the device and the video gets exported but there's no audio. This leads me to believe that I must be using an audio format that the device doesn't support but OS X does, as the simulator uses what OS X uses. I've tried m4a, aiff, and aifc and have had no luck! Any ideas??
I have a very similar problem. It does not seem to do with codecs, as I made a separate test case that runs fine with the same video. There’s a related question that says the problem might be in playing the same assets using MPMoviePlayerController. That got me on the right track (sort of).
In my case the trouble stem from using the assets in an AVPlayer during the export. I was not able to find the exact combination that causes the export to drop the audio track – in the separate test project the export runs fine even though the asset plays in AVPlayer at the same time. After several hours of trying to find the exact cause I gave up and simply popped the asset out of the player using replaceCurrentItemWithPlayerItem:nil during export. It’s a hack, but it works.
AVFoundation is a very powerful framework, but God I wish it wasn’t so finicky or at least logged more errors instead of silently producing garbage.

Sound on the iPhone: Finch: Ensuring that sound actually plays

I am using Finch to play sound. Works great. One exception: I get an incoming call, answer the call, hang up. Go back to the app. Now sounds don't seem to play correctly anymore. What is the most resource-friendly way of ensuring they will? I guess the audio session is somehow closed...
Consider just using CocosDenshion sound library. we have found it solves all problems. not perfect but very reliable. hope it helps!
Note there is also the ObjectAL library, which, is possibly simply better than CocosDenshion.
You have to setup your own OpenAL audio interrupter.
An example of how to do this is found in Apple's SDK example called oalTouch.
See:
https://developer.apple.com/library/ios/#samplecode/oalTouch/Introduction/Intro.html

Sound Not Playing In iOS - Not A Source Code Problem

I want to play a sound in my application. Nothing special, just a little WAV file. The file exists in the device in my main bundle, and I've got both the AVFoundation and AudioToolbox frameworks added. I have alternately tried using both of them, testing out every bit of sample code on the net for playing this sound. It won't work. So what else could be wrong, given that the file exists and the code snippet probably isn't the problem?
Is it to do with imports? I import the necessary .h files for the frameworks at the top of the file.
I've noticed that one of the methods requires there to be a delegate that implements a particular protocol. Is this necessary? Some examples require it, others don't. What do I need to implement for this?
This fails to play the sound both on the device and the simulator. HAve I overlooked antyhing else?
Is it to do with imports?
No. Problems with imports will be apparent at build time.
I've noticed that one of the methods
requires there to be a delegate that
implements a particular protocol. Is
this necessary?
No. The AVAudioPlayer delegate is optional.
This fails to play the sound both on
the device and the simulator. HAve I
overlooked antyhing else?
The most likely explanation is that the file is not being properly referenced. Alternatively, the file may be in a non-standard format for and the player chokes on it silently. Try testing with another file type.
In my case today, an mp3 worked fine on the Simulator (and in iTunes and everywhere else I tested it), but not on a device. I converted the mp3 to an aif and IT worked fine on the device.
I know this is more worthy of a comment than an answer, but I lack the rep to comment.