wxr
2020-06-16 f6fd8acd7c53c44187e70b4709443318a628f4b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using Android.Content;
using Android.Media;
 
namespace com.hdl.on
{
    public static class Volume
    {
        /// <summary>
        /// 音量变化事件
        /// </summary>
        public static Action<int> VolumeChange;
        /// <summary>
        /// 是否需要更新当前音量
        /// </summary>
        static bool isNeedUpdate = true;
        /// <summary>
        /// 设置当前音量
        /// </summary>
        /// <param name="volume">Volume.</param>
        public static int MusicVolume {
            set {
                if (!isNeedUpdate) {
                    return;
                }
                isNeedUpdate = false;
                AudioManager audioManager = (AudioManager)Shared.Application.Activity.GetSystemService (Context.AudioService);
                float tempVolume = value / 100.0f * audioManager.GetStreamMaxVolume (Stream.Music);
                audioManager.SetStreamVolume (Stream.Music, (int)tempVolume, 0);
            }
        }
        /// <summary>
        /// 初始化当前音量播放类型是媒体
        /// </summary>
        public static void Init ()
        {
            Shared.Application.Activity.VolumeControlStream = Stream.Music;
        }
    }
}