14

So I was trying to use AudioToolbox with RubyMotion,

1, Added

app.frameworks << 'AudioToolbox'

in Rakefile,

2, And in one of my simple view controller method, simply added

p AudioFileID

3, Then rake,

4, Given an error,

uninitialized constant RecorderViewController::AudioFileID (NameError)

Obviously AudioFileID which in AudioToolbox was not loaded, I tried similar thing in CoreAudio, it works well. Do I need to require or something? Any idea? Thanks.

simsicon
  • 311
  • 1
  • 7

3 Answers3

0

I think adding AudioToolbox to your frameworks probably is loading the toolkit, unless you're seeing errors during the build. You don't need to require anything else.

I have a RubyMotion program that calls AudioToolbox functions like AudioFileOpenURL and AudioFileGetProperty without error. Since AudioFileID is a struct, I don't think it is defined as a bare constant to use. If you are getting errors when using AudioToolbox functions, please update this question or perhaps start a new one.

slothbear
  • 2,016
  • 3
  • 21
  • 38
0

I created a ticket on RubyMotion bug tracker and tinkered with this issue for 3 days by myself, here is what I found

you have to patch AudioToolbox.bridgesupport for each iOS version you're targeting (/Library/RubyMotion/data/ios/6.1/BridgeSupport/AudioToolbox.bridgesupport) until this issue is fixed in upcoming RubyMotion release

Replace this line <cftype type='^{OpaqueAudioFileID=}' name='AudioFileID'/>

with <opaque type='^{OpaqueAudioFileID=}' name='AudioFileID'/>

this way RubyMotion won't treat AudioFileID as a structure defined somewhere (hence uninitialized constant error) and you'll be able to instantiate a pointer to AudioFileID by calling Pointer.new AudioFileID.type

Sugan S
  • 1,782
  • 7
  • 25
  • 47
Pavel Tisunov
  • 31
  • 1
  • 3
0

To use the symbols from the AudioToolbox framework, you need to explicitly require them in your Ruby code. In this case, you should require the 'audio_toolbox' gem in your view controller file before using the symbols from the framework. Here's an example:

require 'audio_toolbox'

class RecorderViewController < UIViewController
  def your_method_name
    p AudioFileID
  end
end

Make sure you have the 'audio_toolbox' gem installed in your project. You can add it to your Gemfile if you haven't done so already:

gem 'audio_toolbox'
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129