Last active
May 7, 2021 20:26
Unity上からiOS端末のシステムボリュームを取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.InteropServices; | |
namespace iOSNative | |
{ | |
/// <summary> | |
/// `AVAudioSession`のBridge | |
/// </summary> | |
/// <remarks> | |
/// - https://developer.apple.com/documentation/avfaudio/avaudiosession | |
/// </remarks> | |
public static class AVAudioSessionBridge | |
{ | |
/// <summary> | |
/// システムボリューム | |
/// </summary> | |
/// <remarks> | |
/// NOTE: | |
/// - 値は[0f~1f]の範囲 | |
/// - iOS実機以外は常に1fを返す | |
/// </remarks> | |
public static float OutputVolume | |
{ | |
get | |
{ | |
#if !UNITY_EDITOR && UNITY_IOS | |
return OutputVolumeNative(); | |
#else | |
return 1f; | |
#endif | |
} | |
} | |
#region P/Invoke | |
[DllImport("__Internal", EntryPoint = "outputVolume")] | |
static extern float OutputVolumeNative(); | |
#endregion P/Invoke | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <AVFoundation/AVFoundation.h> | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
// システムボリュームの取得 | |
// NOTE: 値は[0f~1f]の範囲 | |
// ref: https://developer.apple.com/documentation/avfaudio/avaudiosession/1616533-outputvolume?language=objc | |
float outputVolume() { | |
return [[AVAudioSession sharedInstance] outputVolume]; | |
} | |
#ifdef __cplusplus | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment