繁体   English   中英

更改cordova-nativeaudio插件

[英]Change the cordova-nativeaudio plugin

我正在尝试更改Cordova插件,以便可以从javascript更改iOS音乐类别,但在Cordova构建日志中收到警告

知道我的代码有什么问题吗? 第一个参数有效,但第二个无效

audio.setCategory('AVAudioSessionCategoryAmbient', 
                  'AVAudioSessionCategoryOptionMixWithOthers')

和iOS部分:

- (void) setCategory:(CDVInvokedUrlCommand *)command {

    NSArray* arguments = command.arguments;
    NSString *category = [arguments objectAtIndex:0];
    NSString *options = [arguments objectAtIndex:1];

    [[AVAudioSession sharedInstance] setCategory:category withOptions:options error:nil];


    [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
}

我收到以下警告

/project/koeriersapp/Plugins/cordova-plugin-nativeaudio/NativeAudio.m:67:71:警告:向“ AVAudioSessionCategoryOptions”类型的参数(也称为“枚举AVAudioSessionCategoryOptions”)发送“ NSString * __ strong”的整数转换指针不兼容[- Wint-conversion] [[AVAudioSession sharedInstance] setCategory:category withOptions:options错误:无]; ^ ~~~~~~~~~~~~在从/project/koeriersapp/Plugins/cordova-plugin-nativeaudio/NativeAudio.h:11导入的模块'AVFoundation'中:/Applications/Xcode.app/Contents/Developer/Platforms /iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk/System/Library/Frameworks/AVFoundation.framework/Frameworks/AVFAudio.framework/Headers/AVAudioSession.h:364:85:注意:将参数传递给参数“选项”这里-(BOOL)setCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError **)outError NS_AVAILABLE_IOS(6_0); ^

您不能将NSString作为options传递给:

[[AVAudioSession sharedInstance] setCategory:category withOptions:options error:nil]; 

它应该是AVAudioSessionCategoryOptions枚举。

要解决它,您可以将匹配器写为:

AVAudioSessionCategoryOptions optionsOrig = 0;

if([options isEqualToString: @"AVAudioSessionCategoryOptionMixWithOthers"]){
    optionsOrig = AVAudioSessionCategoryOptionMixWithOthers;
}

[[AVAudioSession sharedInstance] setCategory: category withOptions:optionsOrig error:nil];

参考:

- (BOOL)setCategory:(NSString *)category 
    withOptions:(AVAudioSessionCategoryOptions)options 
          error:(NSError * _Nullable *)outError;

在这里查看DOC

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM