如何在这个Phonegap插件中为iOS AudioServices编写停止函数
How to write a stop function for iOS AudioServices in this Phonegap plugin?
我正在使用Phonegap插件SoundPlug来管理我正在构建的HTML5游戏中的音频,尽管它有播放声音的方法,但它没有任何停止声音的方法。播放函数是用PhoneGap.exec("SoundPlug.play","sound.wav")从应用程序的javascript调用的。相关代码如下:
- (void) play:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSBundle * mainBundle = [NSBundle mainBundle];
NSMutableArray *directoryParts = [NSMutableArray arrayWithArray:[(NSString*)[arguments objectAtIndex:0] componentsSeparatedByString:@"/"]];
NSString *filename = [directoryParts lastObject];
[directoryParts removeLastObject];
NSMutableArray *filenameParts = [NSMutableArray arrayWithArray:[filename componentsSeparatedByString:@"."]];
NSString *directoryStr = [directoryParts componentsJoinedByString:@"/"];
NSString *filePath = [mainBundle pathForResource:(NSString*)[filenameParts objectAtIndex:0]
ofType:(NSString*)[filenameParts objectAtIndex:1]
inDirectory:directoryStr];
SystemSoundID soundID;
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
AudioServicesCreateSystemSoundID((CFURLRef)fileURL, &soundID);
AudioServicesPlaySystemSound(soundID);
}
不幸的是,我对Obj-C一无所知,所以我不确定如何为此编写一个合适的停止函数。(我试图处理的确切情况是,当玩家想要静音所有运行的声音时。)
如果需要停止,您真的不应该使用AudioServicesPlaySystemSound。如果phonegap有一个到AVAudioPlayer的桥,这可能是一个更适合用于启动和停止声音的API。
但是,如果您将AudioServicesPlaySystemSound()使用的soundID变量保存在某个位置(在实例变量、全局变量或传递回webview javascript land等中);AudioServicesDisposeSystemSoundID(soundID)可能会停止该soundID产生的系统声音。
相关文章:
- 如何确定javascript已经完成了某些操作.ios上的
- 压缩phonegap中ios的图像插件
- React Native通过Navigator将用户输入数据传递到选项卡栏IOS中的组件
- 如何在iOS应用程序中从Firebase中删除超过6小时的数据
- 是否可以使用iframe API在iOS浏览器上播放youtube视频
- iOS 中的按钮触摸状态
- 在iOS 4.3中未调用UIWebView shouldStartLoadWithRequest
- 在iOS和Android上使用React native时,我还能使用本机第三方lirbraries吗
- 谷歌地图根本不适用于Meteor-iOS
- Facebook登录不适用于iOS的应用内浏览器
- 绕z轴旋转时出现iOS陀螺仪错误
- 触摸启动事件未在iframe iOS 6中启动
- 有没有一种方法可以检测ios<>使用jquery和触发器操作形成导航按钮
- 无法在Cordova 4.0 ios中将jpg/jpeg图像转换为Base64
- iOS鼠标中心绑定只工作一次
- javascript函数访问ios本机功能
- Moment js and IOS
- Firebase updateChildValues适用于IOS,但不适用于Web和Android
- 如何修复:当javascript更改DOM时,iOS会删除CSS文件
- 如何在这个Phonegap插件中为iOS AudioServices编写停止函数