コード例 #1
0
        /// <summary>
        /// Ask for playback time to a native audio player. It is relative to the start of audio data currently loaded in **seconds**.
        /// The API is very time sensitive and may or may not change the value in the same frame. (depending on where you call it in the script)
        /// [Android] Because of how "stop hack" was implemented, any stopped audio will have a playback time equals to audio's length (not 0)
        ///
        /// This behaviour is similar to when calling `AudioSettings.dspTime` or `audioSource.time` property, those two are in the same update step.
        ///
        /// Note that `Time.realTimeSinceStartup` is not in an update step unlike audio time, and will change every time you call even in 2 consecutive lines of code.
        ///
        /// [iOS] Get AL_SEC_OFFSET attribute. It update in a certain discrete step, and if that step happen in the middle of
        /// the frame this method will return different value depending on where in the script you call it. The update step timing is THE SAME as
        /// `AudioSettings.dspTime` and `audioSource.time`.
        ///
        /// I observed (in iPad 3, iOS 9) that this function sometimes lags on first few calls.
        /// It might help to pre-warm by calling this several times in loading screen or something.
        ///
        /// [Android] Use GetPosition of SLPlayItf interface. It update in a certain discrete step, and if that step happen in the middle of
        /// the frame this method will return different value depending on where in the script you call it. The update step timing is INDEPENDENT from
        /// `AudioSettings.dspTime` and `audioSource.time`.
        /// </summary>
        public float GetPlaybackTime()
        {
#if UNITY_IOS
            return(NativeAudio._GetPlaybackTime(InstanceIndex));
#elif UNITY_ANDROID
            return(NativeAudio.getPlaybackTime(InstanceIndex));
#else
            return(0);
#endif
        }