简体   繁体   English

如何将音频从设备扬声器路由到蓝牙扬声器?

[英]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

Have you tried this? 你有尝试过吗?

do {
       try AVAudioSession.sharedInstance().setCategory(AVAudioSessionPortBluetoothA2DP) 
   } catch _ {

   }

This maybe helpful. 可能会有所帮助。

暂无
暂无

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

相关问题 如何将iPhone音频路由到蓝牙扬声器 - how to route iPhone audio to the bluetooth speaker 将音频重新路由到蓝牙扬声器 - Reroute Audio to Bluetooth Speaker iOS - 可以录制蓝牙耳机麦克风的音频并播放设备扬声器 - iOS - is possible to record audio from Bluetooth headset mic and play in device speaker 从无线耳机录制音频并通过蓝牙扬声器播放 - Record Audio From wireless Headset and Play it Through Bluetooth speaker 如何获取可用的输出音频源列表(扬声器,耳机,蓝牙) - How to get list of available output audio source ( Speaker, earphone, bluetooth ) 如何在不使用AudioSessionSetProperty的情况下将音频路由到扬声器? - How Do I Route Audio to Speaker without using AudioSessionSetProperty? 核心音频:使用扬声器,是否可以路由到内置扬声器-AVAudioSessionPortBuiltInReceiver(不对扬声器) - Core Audio: Working with Speaker, Is it possible to route to the internal speaker- AVAudioSessionPortBuiltInReceiver(Not to loud speaker) iOS可以同时通过蓝牙和设备扬声器播放两个独立的音频流吗? - Can iOS play two independent audio streams through bluetooth and device speaker simultaneously? 在扬声器、内置麦克风、蓝牙或无音频之间切换音频 - Switch Audio Between Speaker, Built in mic, Bluetooth or No Audio 在iOS中以编程方式将呼叫音频路由从蓝牙耳机更改为iPhone扬声器 - Change Call Audio routing from Bluetooth Headset to iPhone Speaker in iOS programatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM