Xamarin.iOS中的声音静音(iOS版本> 11) [英] Mute sound in Xamarin.iOS (iOS version >11)

查看:95
本文介绍了Xamarin.iOS中的声音静音(iOS版本> 11)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XamarinMediaManager (使用MPMusicPlayerController构建)来构建音频播放器iOS,我正在寻找一种方法来使按钮单击时的声音静音,这在iOS 9上效果很好:

I am using XamarinMediaManager (built using MPMusicPlayerController) to Build an audio player for iOS, i am looking for a way to mute the sound on a button click, this works perfectly on iOS 9:

MPMusicPlayerController.ApplicationMusicPlayer.Volume = 0 

但是它似乎在较新的版本上已被弃用: https://developer.apple.com/documentation/mediaplayer/mpmusicplayercontroller/1624567-volume

But it looks like it is deprecated on newer versions: https://developer.apple.com/documentation/mediaplayer/mpmusicplayercontroller/1624567-volume

如何使用另一种方式实现同​​一目标? (我不想建立一个完整的音量管理器,我只想设置音量).

How to achieve the same thing using another way? (i am not looking to build an entire volume manager, i just want to set the volume).

任何帮助将不胜感激.

推荐答案

根据发布的文档,它已不推荐使用MPVolumeView,这是其用于调整音频输出的新滑块视图.我知道您不希望将滑块添加到UI并希望以编程方式进行操作,基于此

According to the documentation posted it's been deprecated for MPVolumeView, which is their new slider view for adjusting audio output. I know you're not looking to add the slider to your UI and want to do it programmatically, which based on this post you can still technically do it. Although, it does feel kind of hacky.

这里是C#等效项:

UISlider slider = null;
var volumeView = new MPVolumeView();
foreach (var view in volumeView.Subviews)
{
    if (view is UISlider)
    {
        slider = (UISlider)view;
        break;
    }
}

slider.Value = 0;

值得注意的是,我不确定这是否会真正影响XamarinMediaManager播放音频的方式.

It's worth noting I'm unsure whether if this will actually effect how XamarinMediaManager is playing the audio.

这篇关于Xamarin.iOS中的声音静音(iOS版本> 11)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆