- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法在 TriggerIO 插件中维护实例,因此我需要一种静态方式来响应我的 AVAudioPlayer
的事件。但是,我无法设置 player.delegate
至audio_API
,所以我有点卡住了。
音频API.h:
@interface audio_API : NSObject<AVAudioPlayerDelegate>
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
最佳答案
委托(delegate)必须是一个对象,但是 audio_API
是类型名称。但是,您可以简单地将委托(delegate)指定为 audio_API
的类对象。 :
player.delegate = (id<AVAudioPlayerDelegate>)[audio_API class];
[audio_API class]
返回
Class
,而不是
Class<AVAudioPlayerDelegate>
,即使您在
audio_API
的接口(interface)上指定委托(delegate)
关于ios - 使用类作为静态 AVAudioPlayer 的 AVAudioPlayerDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16007776/
我正在尝试暂停 AVAudioPlayer如果当前正在播放。当我调试我的代码并检查时 AVAudioPlayer ,我看是分配的。当我尝试访问它的方法/属性(即 myAudioPlayer isPla
在我的应用程序中,我有 52 mp3,当我加载我的 View Controller 时,我以这种方式分配所有 52 mp3: NSString *pathFrase1 = [NSString stri
我在哪里可以找到 AVAudioPlayer 中所有支持的音频格式的列表?我试图在文档中找到有关它的任何信息,但我做不到。谢谢! 最佳答案 根据documentation of AVAudioPlay
我正在使用AVAssetReader读取ipod库 Assets 音频数据并渲染波形图像。这是使用我在对this question的回答中描述的代码进行的 这有时是在AVAudioPlayer实例播放
我正在创建和播放 AVAudioPlayer 如下: playerOne = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: path)
我被困在一些与 AVAudioPlayer 相关的奇怪内存泄漏问题上,在尝试了所有想到的东西后我需要帮助。 这是问题的简短描述 - 代码紧随其后。 我初始化我的播放器并开始无限循环播放音轨(无限循环或
我在使用 AVAudioPlayer 播放某些文件时遇到问题。当我尝试播放某个 m4a 时,效果很好。它也适用于我尝试过的 mp3。然而,无论我尝试播放它们的顺序如何,它每次都会在一个特定的 mp3
我会保持简短和甜蜜 - 在我为自己购买 iPhone 开发者计划之前,我正在构建一个应用程序只是为了练习。 我正在尝试 AVFoundation.framework,但一直遇到一个错误,该错误只会让我
场景如下...... 使用 AVAudioPlayer 播放背景 mp3, 在播放背景音乐时使用 AVPlayer 播放视频(无音频视频), 现在,如果尝试通过设备静音将音频静音,背景音频不会静音,
我有一个简单的问题:我正在将 mp3 文件加载到 NSData 对象中,然后在游戏中使用 AVAudioPlayer 来播放它。大约每隔一秒,帧速率就会下降,您可以看到屏幕上出现卡顿现象。这并不是一个
我喜欢更新现有的 iPhone 应用程序,该应用程序使用 AudioQueue 来播放音频文件。电平(peakPowerForChannel、averagePowerForChannel)从 0.0f
我得到了以下代码: - (id)init { if (self = [super init]) { UInt32 sessionCategory = kAudioSession
当我打开UIImagePickerController时,我可以显示设备的相机输入流。 但是当我使用 [player play] 播放 AVAudioPlayer 时,相机会停止工作。 我该如何处理这
我在使用 AVAudioPlayer 时遇到问题,我想重置当前正在播放的播放器并再次播放。 我尝试了以下方法,但没有成功: 声音播放一次,但第二次我选择按钮时它停止声音,第三次再次启动声音。 //St
所以我刚刚注意到,在我的 iPod Touch 上,当我的应用程序触发使用 AVAudioPlayer 播放的短 wav 文件时,音乐会暂停。这是正常的吗? 我找不到任何对此的引用,似乎会在某处注明。
我想控制AVAudioplayer中音频的播放速度。这可能吗?如果是这样,你会怎么做? 最佳答案 现在可以更改播放速度。 示例代码: player = [[AVAudioPlayer alloc] i
我只是想知道你如何重复 AVAudioPlayer? 最佳答案 将属性 numberOfLoops 设置为 -1,它将进入无限循环。 关于iphone - 如何重复播放 AVAudioPlayer?,
我有一个 AVAudioPlayer 正在播放一些音频(废话!) 当用户按下按钮时启动音频。当他们释放它时,我希望音频淡出。 我正在使用界面构建器...所以我尝试连接“touch up inside”
我有一个带有两个按钮的 AVAudioPlayer:播放和停止。 播放时播放按钮隐藏,反之亦然。 问题是当我尝试按下停止按钮时发生崩溃,就在播放结束时,在调用方法“audioPlayerDidFini
我观察到的奇怪的行为与AVAudioPlayer工作时 以下是代码: AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContent
我是一名优秀的程序员,十分优秀!