[英]How to route audio from device speaker to bluetooth speaker?
I am using AVPlayer
to play music in my code. 我正在使用AVPlayer
在我的代码中播放音乐。 I know I can use MPVolumeView
from MediaPlayer
to route between speakers, but I am looking for something different(Because I am developing the application in Ionic and I am not able to find some plugin that can perform such thing, plugin which I use is cordova-plugin-media). 我知道我可以使用MediaPlayer
MPVolumeView
在扬声器之间进行路由,但是我正在寻找不同的东西(因为我正在Ionic中开发应用程序,而我找不到能够执行此操作的插件,因此我使用的插件是cordova -plugin-media)。
I have searched about how to create it and found some answers like I can switch using AVAudioSession
. 我搜索了如何创建它,并找到了一些答案,例如可以使用AVAudioSession
进行切换。 I am not able to find some code related to it so if anyone can help it would be great. 我找不到与之相关的一些代码,因此,如果有人可以帮助,那就太好了。
Another thing is that if I change this forcefully how will it behave with Control Center. 另一件事是,如果我强行更改此设置,它将在Control Center中表现如何。
You can still use MPVolumeView
with IONIC as plugin, you just need to control UITouchUpInside
through code. 您仍然可以使用带有IONIC的MPVolumeView
作为插件,只需要通过代码控制UITouchUpInside
。
Check this if helps. 检查是否有帮助。
- (void) currentOutputs:(CDVInvokedUrlCommand*)command {
if(!mpVolumeView){
mpVolumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
mpVolumeView.showsVolumeSlider = FALSE;
[self.webView.superview addSubview:mpVolumeView];
[mpVolumeView setAlpha:0.01];
}
UIButton* btn = nil;
for (UIView *view in [mpVolumeView subviews]){
if ([view.class.description isEqualToString:@"MPButton"]){
btn = (UIButton*)view;
break;
}
}
if(btn){
[btn sendActionsForControlEvents:UIControlEventTouchUpInside];
}
}
Working plugin 工作插件
https://github.com/jaymehtasa/cordova-plugin-audioroute https://github.com/jaymehtasa/cordova-plugin-audioroute
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.