1
我無法在TriggerIO插件中維護實例,因此我需要一種靜態方式來響應我的AVAudioPlayer
的事件。但是,我不能將player.delegate
設置爲audio_API
,所以我有點卡住了。將類用作AVAudioPlayerDelegate用於靜態AVAudioPlayer
audio_API.h:
@interface audio_API : NSObject<AVAudioPlayerDelegate>
audio_API.m:
static AVAudioPlayer* player = nil;
@implementation audio_API
+ (void)play:(ForgeTask*)task {
// parse the file url from the file object
ForgeFile* file = [[ForgeFile alloc] initWithFile:[task.params objectForKey:@"file"]];
NSString* fileURL = [file url];
NSLog(@"Playing file at %@", fileURL);
NSURL* url = [NSURL URLWithString:fileURL];
// TESTING
url = [[NSBundle mainBundle] URLForResource:@"seconds.m4a" withExtension:nil];
// END TESTING
NSAssert(url, @"URL is invalid.");
// create the player
NSError* error = nil;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if(!player)
{
NSLog(@"Error creating player: %@", error);
};
// player.delegate = audio_API;
[player play];
[task success:nil];
}
+ (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
if (flag) {
[ForgeLog d:@"Audio finished playing successfully."];
} else {
[ForgeLog d:@"Audio did not finish playing successfully."];
}
// call the audio.finishedPlaying event
[[ForgeApp sharedApp] event:@"audio.finishedPlaying" withParam:nil];
}
+ (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
{
[ForgeLog d:@"Audio had error decoding."];
[ForgeLog e:error];
// call the audio.decodeErrorOccurred event
[[ForgeApp sharedApp] event:@"audio.decodeErrorOccurred" withParam:nil];
}
@end
如何使這項工作任何想法?
謝謝。
當您嘗試設置委託時,有什麼問題? –
'/Users/gsquare567/forge-workspace/plugins/audio/inspector/ios-inspector/ForgeModule/alert/audio_API.m:47:23:意外的接口名稱'audio_API':預期的表達式'當我嘗試'player.delegate = audio_API;' – Garrett