尝试创建AudioComponentDescription结构时Rubymotion抛出NameError

时间:2014-04-09 10:48:21

标签: core-audio rubymotion

我将这个Objective-C代码转换为Rubymotion并遇到一些意外错误

AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
// ...

在RM

desc = AudioComponentDescription.new
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
# ...

我收到错误<NameError: uninitialized constant AudioComponentDescription>

更新

我尝试了以下内容 - 创建了两个类似的类,调用AudioComponentDescription。其中一个是Objective-C,其中一个是Rubymotion。

这是一个非常简单的应用程序,其中没有别的东西。

Rake文件:

    # -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'

begin
  require 'bundler'
  Bundler.require
rescue LoadError
end

Motion::Project::App.setup do |app|
  app.name = 'CoreAudioSandbox'
  app.deployment_target = "6.0"
  app.frameworks += %w[ AudioToolbox AVFoundation CoreAudio AudioUnit AudioComponent ]
  app.vendor_project('vendor/AudioController', :static)
end

Objective-C类:

#import <AudioToolbox/AudioToolbox.h>

@interface AudioController : NSObject
{
}

#import "AudioController.h"

@implementation AudioController

#pragma mark init

- (id)init
{
    AudioComponentDescription desc;
    desc.componentType         = kAudioUnitType_Output;
    desc.componentSubType      = kAudioUnitSubType_RemoteIO;
    desc.componentFlags        = 0;
    desc.componentFlagsMask    = 0;
    desc.componentManufacturer = kAudioUnitManufacturer_Apple;
    return self;
}

Rubymotion Class

class AudioController2

  def init
    desc = AudioComponentDescription.new
    desc.componentType         = KAudioUnitType_Output
    desc.componentSubType      = KAudioUnitSubType_RemoteIO
    desc.componentFlags        = 0
    desc.componentFlagsMask    = 0
    desc.componentManufacturer = KAudioUnitManufacturer_Apple
    return self
  end

end

App Delegate

def application(application, didFinishLaunchingWithOptions: launchOptions)    
  NSLog("Initializing AudioController (Objective-C)")
  AudioController.alloc.init
  NSLog("Initializing AudioController2 (Rubymotion)")
  AudioController2.alloc.init
  true
end

初始化AudioController实例,但在AudioController2实例上呱呱叫。

这是错误:

2014-04-09 19:54:01.218 CoreAudioSandbox[19313:70b] Initializing AudioController (Objective-C)
2014-04-09 19:54:01.219 CoreAudioSandbox[19313:70b] Initializing AudioController2 (Rubymotion)
(main)> 2014-04-09 19:54:01.593 CoreAudioSandbox[19313:70b] audio_controller2.rb:4:in `init': uninitialized constant AudioController2::AudioComponentDescription (NameError)
    from app_delegate.rb:11:in `application:didFinishLaunchingWithOptions:'
2014-04-09 19:54:01.596 CoreAudioSandbox[19313:70b] *** Terminating app due to uncaught exception 'NameError', reason: 'audio_controller2.rb:4:in `init': uninitialized constant AudioController2::AudioComponentDescription (NameError)
    from app_delegate.rb:11:in `application:didFinishLaunchingWithOptions:'
'
*** First throw call stack:
(
    0   CoreFoundation                      0x025a71e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x002048e5 objc_exception_throw + 44
    2   CoreAudioSandbox                    0x001544da _ZL10__vm_raisev + 346
    3   CoreAudioSandbox                    0x001545c2 rb_vm_raise + 226
    4   CoreAudioSandbox                    0x00059ef1 rb_exc_raise + 17
    5   CoreAudioSandbox                    0x00053737 rb_name_error + 135
    6   CoreAudioSandbox                    0x0010d2f5 rb_mod_const_missing + 165
    7   CoreAudioSandbox                    0x00148f4d _ZL20dispatch_rimp_callerPFP11objc_objectS0_P13objc_selectorzEmS1_iPKm + 46445
    8   CoreAudioSandbox                    0x0012f94a rb_vm_dispatch + 6474
    9   CoreAudioSandbox                    0x0010e166 rb_const_get_0 + 1046
    10  CoreAudioSandbox                    0x0010e260 rb_const_get + 32
    11  CoreAudioSandbox                    0x0014c512 rb_vm_const_lookup_level + 338
    12  CoreAudioSandbox                    0x000045a3 vm_get_const + 227
    13  CoreAudioSandbox                    0x0000cc08 rb_scope__init__ + 104
    14  CoreAudioSandbox                    0x00148f4d _ZL20dispatch_rimp_callerPFP11objc_objectS0_P13objc_selectorzEmS1_iPKm + 46445
    15  CoreAudioSandbox                    0x0012f94a rb_vm_dispatch + 6474
    16  CoreAudioSandbox                    0x000147ac vm_dispatch + 1100
    17  CoreAudioSandbox                    0x0001d327 rb_scope__application:didFinishLaunchingWithOptions:__ + 727
    18  CoreAudioSandbox                    0x0001d39f __unnamed_35 + 95
    19  UIKit                               0x0062a14f -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
    20  UIKit                               0x0062aaa1 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1810
    21  UIKit                               0x0062f667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    22  UIKit                               0x00643f92 -[UIApplication handleEvent:withNewEvent:] + 3517
    23  UIKit                               0x00644555 -[UIApplication sendEvent:] + 85
    24  UIKit                               0x00631250 _UIApplicationHandleEvent + 683
    25  GraphicsServices                    0x045e1f02 _PurpleEventCallback + 776
    26  GraphicsServices                    0x045e1a0d PurpleEventCallback + 46
    27  CoreFoundation                      0x02522ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    28  CoreFoundation                      0x025229db __CFRunLoopDoSource1 + 523
    29  CoreFoundation                      0x0254d68c __CFRunLoopRun + 2156
    30  CoreFoundation                      0x0254c9d3 CFRunLoopRunSpecific + 467
    31  CoreFoundation                      0x0254c7eb CFRunLoopRunInMode + 123
    32  UIKit                               0x0062ed9c -[UIApplication _run] + 840
    33  UIKit                               0x00630f9b UIApplicationMain + 1225
    34  CoreAudioSandbox                    0x000034ac main + 156
    35  libdyld.dylib                       0x03b98701 start + 1
    36  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NameError

0 个答案:

没有答案