How to export mp3 file with AVAssetWriter - ios

I'm trying to export my asset as an .mp3 file using AVAssetWriter.
Here's how I create an instance of it:
writer = try! AVAssetWriter(url: outputURL,
fileType: AVFileType.mp3)
Unfortunately, it throws the error:
[AVAssetWriter initWithURL:fileType:error:] Invalid file type UTI.
Available file types are: com.scenarist.closed-caption, org.w3.webvtt,
public.aiff-audio, com.apple.m4v-video,
org.3gpp.adaptive-multi-rate-audio, com.apple.m4a-audio,
com.microsoft.waveform-audio, com.apple.coreaudio-format,
public.mpeg-4, com.apple.itunes-timed-text, com.apple.quicktime-movie,
public.aifc-audio
I'm running this code on macOS 10.15.
I find it hard to believe that there's no support for exporting an mp3 file. Can anyone guide me on how to make it work?

I find it hard to believe that there's no support for exporting an mp3 file
Overcome your difficulty and believe it. Due to a complex of copyright issues, Apple has no license to provide any native capacity to create MP3 files. You might find some third party library that can do it, but you won't do it with AVAssetWriter.

Related

How do I specify a file type for importing .obj files?

I'm trying to get my app to recognize .obj files for importing.
I've tried to follow the instructions in this WWDC video.
I've tried specifying as both an Imported UTI, and an Exported UTI. Neither causes the file to be openable in UIDocumentBrowserViewController (the document icon is grayed). I don't understand how my native document format is openable in the browser either. I've tried deleting and reinstalling the app from the device.
What am I missing? Why isn't this simple?
Here's what I've got:
It turns out iOS already knows about .obj files. On macOS, I ran the following:
mdls myfile.obj
Which among other things shows:
kMDItemContentType = "public.geometry-definition-format"
kMDItemContentTypeTree = (
"public.content",
"public.geometry-definition-format",
"public.text",
"public.data",
"public.item",
"public.3d-content"
)
So the UTI is public.geometry-definition-format. I don't know if that already specifies the extension or is a more generic type.
The following worked to make the files openable in UIDocumentBrowserViewController:
The UTI isn't declared in the documentation (what a surprise!), so I'd recommend using mdls to look up UTIs.

Loading collada file from webserver in scenekit

I am working with SceneKit and Collada file. Now, I am able to load the collada file inside art.scnassets folder as well as in my project root directory. I am getting an error when i am trying to load the file from a local webserver. Any reason why I cannot do this?
let url = NSURL(string: "http://localhost:8888/new.dae")
let scn = try! SCNScene(URL: url!, options: nil)
2016-07-31 17:41:29.537 biOS[3863:254446] SceneKit IO: error, COLLADA files are not supported on this platform.
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=259 "The document "new.dae" could not be opened." UserInfo={NSURL=http://localhost:8888/new.dae, NSLocalizedDescription=The document "new.dae" could not be opened., NSLocalizedRecoverySuggestion=Collada is not supported by this version of SceneKit}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.8/src/swift/stdlib/public/core/ErrorType.swift, line 54
My goal is to read the collada file from a websever and then offer the user to download the file onto the device. I do not know why I am getting the error. By the way, I did a document preview to render the file, and it was successfully about to render document in xml. So, it is not a case of access to the file. Please help!
Any reason why I cannot do this?
Yes unfortunately.
During the build process XCode compiles your collada to .scn files. This is a scenekit specific binary file format, doing this reduces the size of the asset files (collada files are XML based) improving the load performance. SceneKit running on an iOS device does not load collada files, only .scn files.
You could look at using ModelIO to load resources that aren't part of your application, but I note collada isn't one of the supported formats.
You can also convert your dae files just like Xcode does using terminal.
Build a project with Xcode that has a dae and check the commands executed by Xcode (search for scntool)
Related: COLLADA transformations in SceneKit
I have found the AssetImportKit framework to solve this problem. The framework allows you to import Assimp supported file formats directly in SceneKit at runtime (macOS & iOS). The library supports:
Geometry Materials (with color, embedded textures and external textures)
Cameras and Skeletal animations
Serialization to .scn format

How to Play mp3 file from memory in delphi?

I am downloading a mp3 file from the internet to memory using InternetReadFile. This works great, I can dump the file on disk and then play it, but I want to play the file without dumping it on disk.
Is there a library i can use to achieve this functionality ? Some docs on how to use the library would be useful too.
Thanks in advance.
You can use the BASS Delphi audio library
On the other side, search for "MP3" on the 3D Buzz site. They have a very good series of video tutorials that walk you through the creation of your own MP3 player in Delphi using this library.

Why do I get this error "EMCIDeviceError" when opening some wav files in my program

Hey I have this program that has been working fine until I tried to open this one wav file? Not sure what the problem is or that I understand it? Do I need to find a new component to use for this file or what? I am using Delphi 4 Pro and the standard VCL component for Media Player. I am looking for a good new component that offers more help with wav and mp3 files too but not found what I am looking for yet?
Possible reasons for a EMCIDeviceError:
It's known that mediaplayer has problems with some MP3 files, depending from the version of the mediaplayer that is installed on the machine. Try updating mediaplayer on the problem-machine(s).
Maybe the sound drivers just need updating
You also get an EMCIDeviceError if there is no soundcard, or the drivers are corrupted, or there are no drivers at all. But then it would not play any other MP3 files, so I just mention this to help out other Forum readers.
This kind of EMCIDeviceError is raised when you provide a fully qualified filename to the TMediaPlayer.FileName property which exceeds certain no of characters. It has nothing to do with having spaces in the filepath. For example if you play sounds from the EXE directory and just provide the relative shortname, no error seems to happen. Also with absolute filename from elsewhere, if it is shorter than a certain limit, there is no error. I encountered it in XE5 and have resorted to sndPlaySound().

Ruby/Rails Audio Conversion Plugins?

I am looking for a good gem/plugin to convert user-uploaded audio files to different formats. One format in particular that I am interested in is converting to Apple .caf with ima4 compression for inclusion in an iPhone app.
I have been using afconvert on my mac for this so far, but I need to do it on my linux box, server-side. Ideally, I would be able to work into paperclip.
As an additional solution, ffmpeg could work, but I have not seen any .caf options for it. Anybody know of one?
The Sound eXchange project supports lots of audio file conversions. I've used this in the past to convert aiff files output by the OS X "say" program to ulaw files for Asterisk. This yields rather nice text-to-speech. For my purposes, I also found a Ruby extension on github called sox-ruby that wraps the libsox functions directly.

Resources