ドキュメント

Unity Engine

Unity Engine

GetAudioSampleRate(ushort)

Get the audio track sampling rate in hertz (Hz).
読み終わるまでの所要時間 1 分最終更新 1ヶ月前

Definition

public uint GetAudioSampleRate(ushort audioTrackIdx)

Parameters

audioTrackIdx

Index of the audio queried audio track.

Returns

Type

Description

uintThe sampling rate in hertz.

Remarks

The audio sampling rate is the number of times per second a sample of audio is captured. Higher sample rates usually result in more realistic sounds and better sound quality, but files are larger. This is useful to know so that you can cater your audio to different devices. A VideoClip could have multiple audio tracks for different quality levels, which you can change depending on the device.
Additional Resources: VideoPlayer.EnableAudioTrack.

Examples

using UnityEngine;using UnityEngine.Video;public class AudioSampleRateExample : MonoBehaviour{ VideoPlayer videoPlayer; void Start() { videoPlayer = GetComponent<VideoPlayer>(); // Get the VideoClip from the VideoPlayer VideoClip clip = videoPlayer.clip; if (clip != null) { // Get the number of audio tracks in the VideoClip int audioTrackCount = clip.audioTrackCount; // Loop through each audio track and output their audio sample rate. for (ushort i = 0; i < audioTrackCount; i++) { Debug.Log("Audio track " + i + " has the following audio sampling rate: " + clip.GetAudioSampleRate(i)); } } else { Debug.LogError("No VideoClip assigned to the VideoPlayer."); } }}