3

我正在尝试通过制作 TriggerIO 本机插件来播放语音音频,但是iPodMusicPlayer我无法访问该self对象。

#import "alert_API.h"

@implementation alert_API

+ (void)play:(ForgeTask*)task text:(NSString *)filename {
    NSURL* url = [[NSBundle mainBundle] URLForResource:@"Rondo_Alla_Turka_Short" withExtension:@"aiff"];
    NSAssert(url, @"URL is valid.");
    NSError* error = nil;


    /* ERROR: /Users/gsquare567/forge-workspace/plugins/audio/inspector/ios-inspector/ForgeModule/alert/alert_API.m:45:13: Member reference type 'struct objc_class *' is a pointer; maybe you meant to use '->'? */
    self->player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

    /* ERROR: /Users/gsquare567/forge-workspace/plugins/audio/inspector/ios-inspector/ForgeModule/alert/alert_API.m:45:13: Incomplete definition of type 'struct objc_class' */
    if(!self.player)
    {
        NSLog(@"Error creating player: %@", error);
    }


    [task success:nil];
}

@end

该属性定义在alert_API.h

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface alert_API : NSObject

@property (nonatomic, strong) AVAudioPlayer* player;
+ (void)play:(ForgeTask*)task text:(NSString *)filename;

@end

我需要在这里做什么才能通过player我的 API 访问该属性?

谢谢!

4

1 回答 1

6

您的play:text:方法是静态的,意思self不是引用具有属性的实例,而是引用alert_API. 您可以将方法更改为实例方法(- (void)而不是+ (void)):

- (void)play:(ForgeTask*)task text:(NSString *)filename;

或者如果你想保持方法静态,你必须实现一个返回玩家单例的静态方法:

+ (AVAudioPlayer *)playerInstance;

然后使用[alert_API playerInstance]从您的方法访问播放器。

于 2013-04-11T14:32:50.100 回答