From b8e94316e41eba72d927d5ca7d931b26139ee8ff Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期一, 15 六月 2020 09:12:53 +0800 Subject: [PATCH] 20200612 --- Shared.IOS/Volume.cs | 152 +++++++++++++++++++++++++------------------------- 1 files changed, 76 insertions(+), 76 deletions(-) diff --git a/Shared.IOS/Volume.cs b/Shared.IOS/Volume.cs old mode 100644 new mode 100755 index a38d5e7..6c4ed88 --- a/Shared.IOS/Volume.cs +++ b/Shared.IOS/Volume.cs @@ -1,77 +1,77 @@ -锘�//using System; -//using AVFoundation; -//using Foundation; -//using MediaPlayer; -//using Shared; -//using UIKit; +锘縰sing System; +using AVFoundation; +using Foundation; +using MediaPlayer; +using Shared; +using UIKit; -//namespace com.hdl.on -//{ -// public static class Volume -// { -// /// <summary> -// /// 澹伴煶鍙樺寲浜嬩欢 -// /// </summary> -// public static Action<int> VolumeChange; -// /// <summary> -// /// 璁剧疆褰撳墠闊抽噺 -// /// </summary> -// /// <param name="volume">Volume.</param> -// public static int MusicVolume -// { -// set -// { -// if ((DateTime.Now - dateTime).TotalMilliseconds < 2000) -// { -// return; -// } -// foreach (var view in BaseViewController.MPVolumeView.Subviews) -// { -// if (view.GetType().Name == "UISlider") -// { -// (view as UISlider).SetValue((float)Math.Round(value / 100.0f, 2, MidpointRounding.AwayFromZero), false); -// beforeVolume = (view as UISlider).Value; -// //System.Console.WriteLine("鎺ユ敹鍒版洿鏂伴煶閲忥細" + (float)Math.Round(value / 100.0f, 2, MidpointRounding.AwayFromZero) + " " + beforeVolume); -// break; -// } -// } -// } -// } -// static System.DateTime dateTime = DateTime.MinValue; -// /// <summary> -// /// 涔嬪墠鐨勯煶閲� -// /// </summary> -// static float beforeVolume; -// public static void Init() -// { -// NSNotificationCenter.DefaultCenter.AddObserver(new NSString("AVSystemController_SystemVolumeDidChangeNotification"), -// (obj) => -// { -// //濡傛灉搴旂敤杩涘叆鍚庡彴锛屼笉鎵ц闊抽噺鍙樺寲 -// if (UIApplication.SharedApplication.ApplicationState != UIApplicationState.Active || "Audio/Video" != obj.UserInfo.ObjectForKey(new NSString("AVSystemController_AudioCategoryNotificationParameter")).ToString()) -// { -// return; -// } -// //System.Console.WriteLine("鎺ユ敹鍒伴煶閲忓彉鍖栦簨浠�"); -// dateTime = DateTime.Now; -// var tempValue = obj.UserInfo.ObjectForKey(new NSString("AVSystemController_AudioVolumeNotificationParameter")); -// if (tempValue == null) -// { -// return; -// } -// try -// { -// //鏈夋椂杞崲澶辫触锛屽彲鑳芥湁鏃跺�兼湁闂 -// var volume = 100 * float.Parse(tempValue.ToString()); -// volume = (float)Math.Round(volume, 2, MidpointRounding.AwayFromZero); -// //System.Console.WriteLine("闊抽噺鍙樺寲浜嬩欢锛�" + volume + " " + beforeVolume * 100); -// if (VolumeChange != null && beforeVolume * 100 != volume) -// { -// VolumeChange((int)volume); -// } -// } -// catch { } -// }); -// } -// } -//} +namespace com.hdl.on +{ + public static class Volume + { + /// <summary> + /// 澹伴煶鍙樺寲浜嬩欢 + /// </summary> + public static Action<int> VolumeChange; + /// <summary> + /// 璁剧疆褰撳墠闊抽噺 + /// </summary> + /// <param name="volume">Volume.</param> + public static int MusicVolume + { + set + { + if ((DateTime.Now - dateTime).TotalMilliseconds < 2000) + { + return; + } + foreach (var view in BaseViewController.MPVolumeView.Subviews) + { + if (view.GetType().Name == "UISlider") + { + (view as UISlider).SetValue((float)Math.Round(value / 100.0f, 2, MidpointRounding.AwayFromZero), false); + beforeVolume = (view as UISlider).Value; + //Shared.HDLUtils.WriteLine("鎺ユ敹鍒版洿鏂伴煶閲忥細" + (float)Math.Round(value / 100.0f, 2, MidpointRounding.AwayFromZero) + " " + beforeVolume); + break; + } + } + } + } + static System.DateTime dateTime = DateTime.MinValue; + /// <summary> + /// 涔嬪墠鐨勯煶閲� + /// </summary> + static float beforeVolume; + public static void Init() + { + NSNotificationCenter.DefaultCenter.AddObserver(new NSString("AVSystemController_SystemVolumeDidChangeNotification"), + (obj) => + { + //濡傛灉搴旂敤杩涘叆鍚庡彴锛屼笉鎵ц闊抽噺鍙樺寲 + if (UIApplication.SharedApplication.ApplicationState != UIApplicationState.Active || "Audio/Video" != obj.UserInfo.ObjectForKey(new NSString("AVSystemController_AudioCategoryNotificationParameter")).ToString()) + { + return; + } + //Shared.HDLUtils.WriteLine("鎺ユ敹鍒伴煶閲忓彉鍖栦簨浠�"); + dateTime = DateTime.Now; + var tempValue = obj.UserInfo.ObjectForKey(new NSString("AVSystemController_AudioVolumeNotificationParameter")); + if (tempValue == null) + { + return; + } + try + { + //鏈夋椂杞崲澶辫触锛屽彲鑳芥湁鏃跺�兼湁闂 + var volume = 100 * float.Parse(tempValue.ToString()); + volume = (float)Math.Round(volume, 2, MidpointRounding.AwayFromZero); + //Shared.HDLUtils.WriteLine("闊抽噺鍙樺寲浜嬩欢锛�" + volume + " " + beforeVolume * 100); + if (VolumeChange != null && beforeVolume * 100 != volume) + { + VolumeChange((int)volume); + } + } + catch { } + }); + } + } +} -- Gitblit v1.8.0