Get asset into a sound buffer - ios

I'm playing around with this code example.
What I am trying to do is create a 100% Swift iOS version of this metronome app that allows playing of the MoreCowbell.caf file similar to how they have already done in the macOS example.
It makes logical sense that IF there were some way to reference this MoreCowbell.caf "asset"/"resource" (?) using the URL format, then the above code could work.
Is there a way to do that? If not, then how can we refer to MoreCowbell.caf from code in order get those ones and zeros into the sound buffer?
I have done much googling and looking at apple documentation but and going in circles so thank you for any help!

You can get a URL to files in your Bundle (ie. in your App) by using a method on Bundle (or NSBundle when using Objective-C). It works like this:
let fileURL = Bundle.main.url(forResource: "MoreCowbell", withExtension: "caf")
You can find more information on this in the official documentation.
Also make sure that the file MoreCowbell.caf is included in your Bundle. You do that by setting it's Target Membership

Related

Reading .bundle files in Cocoa Application

I am creating a cocoa web browser using WKWebView and Swift. Like most browsers, they have extensions or plugins. I want to implement the same thing in my web browser. I came across CFPlugin. I want to use this feature but I do not know how. It would be good if you give a sample application.
I haven't tried anything because I don't know what to do
This is how I want my extension to look like
myExtension.bundle/
info.plist
scripts1.js
popoverview.xib
popoverview.swift
script2.js
popuppage.html
image.png
popuppage.css
I want to know how to read the files in the bundle
Thanks!
After a few minutes of trying I found the answer
Bundles are considered as Directories
so you can do something like this
MyBundle.bundle/Contents/Info.plist
MyBundle.bundle/Contents/Resources/MyView.xib

Transloadit Thumbnail Result Image Has Wrong File Extension Capitalization

I am using transloadit to generate a thumbnail image sent from an iOS app that saves both the original image and the thumbnail to Amazon S3. The files get get saved out correctly with one exception. The file name for the thumbnail does not retain the capitalization of the original filename for the file extension, i.e. JPG vs jpg. Here is my template:
I am using the fields to generate the custom path I want--which works fine, however, the output from the "store_thumb" step has this difference:
Is there any way to retain the capitalization? I realize I can just force all of my filenames from the app to lowercase, however, I thought maybe I am just doing something wrong. Any suggestions?
I'm part of Transloadit's developer support team.
First of all, let me assure you there's nothing wrong with what you're doing. Secondly, I've asked our engineers about the issue and we realized it's a limitation caused by our special usage of some of the conversion tools.
We'll do our best to address this on future versions, but we cannot commit on a date. So for now if it's causing you trouble, we recommend using lowercase letters.

iOS AUSampler audiounit - file path issue with EXS audio files?

Following the Apple docs here I have been able to successfully load a GarageBand EXS sampler instrument into AUSampler in my iOS app by recreating, for example the following path within my app directory:
/Sampler Files/Funk Horn Section/nameofaudio.aif
iOS looks for the audio file in the following directory:
file:///Library/Application%20Support/GarageBand/Instrument%20Library/Sampler/Sampler%20Files/Funk%20Horn%20Section/'
However this doesn't work when I create my own EXS file. How does it know to remove the first part of the filepath if GarageBand?? I've even tried creating my EXS instrument and even created in the same GarageBand directory but it makes no difference:
Failed to locate sample '001%20VirusTI%20-%20SeaThr%2314A1B3.aif -- file:///macSSD/Library/Application%20Support/GarageBand/Instrument%20Library/Sampler/Sampler%20Files/VirusTI%20-%20SeaThreeHS%20v2/'
I've also tried manually editing the file path in the exs file with a text editor but nothing works.
The EXS instrument plays fine in logic. But my app can't find it.
Any help greatly appreciated.
The key here is that your source sampler file has to reference samples that come from any of these 'trigger' directory structures to work properly:
"/Sounds/"
"/Sampler Files/"
"/Apple Loops/"
"/EXS Factory Samples/"
"/SoundFont Samples/"
Your sample has to exist in a directory path with one of those triggers in it, and then the path has to match the exact same in your bundle. iOS looks for one of those triggers, then deletes everything before that, and uses that as the new search path in the bundle to find your sample.
It is tricky, but it will work this way if you make sure everything is in order.
I fought with this because my samples were stored in places without any of those keywords, and so it would never find them.

iOS MPMediaPickerController get file data or file url

I'm looking for a way to get a local file:/// url or a byte stream of audio data for a selected audio file using MPMediPickerController/MPMediaItem.
Anyone know if this is possible? So far it seems impossible based on the documentation I'm reading for MediaPlayer framework.
MPMediaItems raw song data
I am struck with the same problem. Please try the above link and let me know if that worked for you.

Check if NSURL is Local File

This is a pretty simple question- how can I check if a NSURL is linking to a local file?
I know, RTFM, but I checked the documentation and I don't seem to see any methods related to this.
The only methods I did find were -isFileReferenceURL and -isFileURL, but I think these only check if the URL directly links to a file.
Note: I'm making an iPhone app, so by "local file" I mean a .html file stored in the project's resources.
Thanks for any help in advance.
The -isFileURL will check if your URL uses the file: scheme. It doesn't check whether it's referencing an actual file.
There is -isFileReferenceURL as of iOS 5 that checks if the url is an file reference. Before 5.0, it did nothing according to the documentation..
Available in iOS 5.0 and later. (Symbol is present in iOS 4, but performs no operation.)
I hope this helps the new-comers...

Resources