菜鸟教程小白 发表于 2022-12-12 11:57:29

ios - AudioToolbox AUAudioFilePlayer 属性说明


                                            <p><p>我对 AUAudioFilePlayer 的以下属性感到困惑。 Apple 的文档充其量是令人困惑的:</p>

<ol>
<li><p>kAudioUnitProperty_ScheduleStartTimeStamp</p></li>
<li><p>kAudioUnitProperty_ScheduledFilePrime</p></li>
<li><p>kAudioUnitProperty_ScheduledFileRegion</p></li>
</ol>

<p>有人可以对每种用法提供一些说明吗?似乎它们的用法重叠?谢谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>是的,这令人困惑。 </p>

<p>StartTime 正是您所想的:它定义了您为该音频单元安排的所有切片/区域的播放时间线的开始。</p>

<p>由于音频数据需要在播放前被拉入 RAM,“启动”基本上是告诉系统开始将音频文件(指定的帧数)读入内存。</p>

<p>您可以选择只播放文件的一部分(在文件中开始一些帧数和/或在文件结尾之前结束一些帧数)。这些被称为“区域”,如果您只想播放音频文件的一部分(或区域),这是您使用的属性。</p>

<p>查看 AudioUnitProperties.h:</p>

<blockquote>
<p>Start Time</p>

<p>The audio unit will not play any slices following initialization or reset, until
                  its start time has been set. The start time establishes the beginning of a
                  timeline: the timestamps of all slices in the schedule are relative to the
                  start time.</p>

<p>Set a start time by setting the kAudioUnitProperty_ScheduleStartTimeStamp
                      property with an AudioTimeStamp structure. If the timestamp contains a valid
                      sample time (timestamp.mFlags &amp; kAudioTimeStampSampleTimeValid), then playback
                      begins when the timestamp passed to the AudioUnitRender function reaches the
                      specified sample time. If the specified sample time is -1, playback begins on
                      the next render cycle.</p>

<p>If the start timestamp does not contain a valid sample time, but does contain a
                      valid host time (timestamp.mFlags &amp; kAudioTimeStampHostTimeValid), then the
                      specified host time is translated to the sample time at which playback will
                      begin. A host time of 0 means &#34;start on the next render cycle.&#34;</p>

<p>The kAudioUnitProperty_ScheduleStartTimeStamp property may be queried to obtain
                      the time at which playback began. If the start time has not yet been reached,
                      the timestamp returned will be whatever the host application last set.</p>

<p>Priming</p>

<p>You should set kAudioUnitProperty_ScheduledFilePrime after scheduling
initial file regions to be played and before starting playback. This SetProperty call will begin reading the audio files and not return until the number of frames specified by the property value have been read.</p>

<p>Scheduling Regions</p>

<p>To schedule the playback of a region of an audio file, set the kAudioUnitProperty_ScheduledFileRegion property. This is a ScheduledAudioFileRegion structure. mTimeStamp.mSampleTime must be valid and is interpreted relative to the unit&#39;s start time -- the start time semantics (using kAudioUnitProperty_ScheduleStartTimeStamp) are identical to those of AUScheduledSoundPlayer. Unlike the ScheduledAudioSlice structures, the unit makes copies of ScheduledAudioFileRegions, so you may create them on the stack or otherwise reuse/dispose of them immediately after scheduling them.</p>
</blockquote></p>
                                   
                                                <p style="font-size: 20px;">关于ios - AudioToolbox AUAudioFilePlayer 属性说明,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/26135973/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/26135973/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - AudioToolbox AUAudioFilePlayer 属性说明