1. <legend id='UnQpA'><style id='UnQpA'><dir id='UnQpA'><q id='UnQpA'></q></dir></style></legend>

    2. <tfoot id='UnQpA'></tfoot>
    3. <small id='UnQpA'></small><noframes id='UnQpA'>

      <i id='UnQpA'><tr id='UnQpA'><dt id='UnQpA'><q id='UnQpA'><span id='UnQpA'><b id='UnQpA'><form id='UnQpA'><ins id='UnQpA'></ins><ul id='UnQpA'></ul><sub id='UnQpA'></sub></form><legend id='UnQpA'></legend><bdo id='UnQpA'><pre id='UnQpA'><center id='UnQpA'></center></pre></bdo></b><th id='UnQpA'></th></span></q></dt></tr></i><div id='UnQpA'><tfoot id='UnQpA'></tfoot><dl id='UnQpA'><fieldset id='UnQpA'></fieldset></dl></div>

        <bdo id='UnQpA'></bdo><ul id='UnQpA'></ul>

        调整播放 AVPlayer 的音量

        Adjusting the volume of a playing AVPlayer(调整播放 AVPlayer 的音量)
        <legend id='swTZH'><style id='swTZH'><dir id='swTZH'><q id='swTZH'></q></dir></style></legend>
        <i id='swTZH'><tr id='swTZH'><dt id='swTZH'><q id='swTZH'><span id='swTZH'><b id='swTZH'><form id='swTZH'><ins id='swTZH'></ins><ul id='swTZH'></ul><sub id='swTZH'></sub></form><legend id='swTZH'></legend><bdo id='swTZH'><pre id='swTZH'><center id='swTZH'></center></pre></bdo></b><th id='swTZH'></th></span></q></dt></tr></i><div id='swTZH'><tfoot id='swTZH'></tfoot><dl id='swTZH'><fieldset id='swTZH'></fieldset></dl></div>

          <tbody id='swTZH'></tbody>

                <small id='swTZH'></small><noframes id='swTZH'>

              1. <tfoot id='swTZH'></tfoot>
                  <bdo id='swTZH'></bdo><ul id='swTZH'></ul>
                  本文介绍了调整播放 AVPlayer 的音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在当前播放的 AVPlayer 项目上获得音量变化的唯一方法是遵循这个过程;

                  The only method for getting a volume change on currently playing AVPlayer items is to follow this process;

                  • 卸载当前播放的 AVPlayerItem 的资源
                  • 获取该 AVPlayerItem 的当前播放时间
                  • 将资源加载到新的 AVPlayerItem
                  • 用新的 AVPlayerItem 替换当前的 AVPlayerItem
                  • 等待 AVPlayer 上的 currentItem 改变
                  • 准备您的 AudioMix 并寻找之前的播放时间

                  我是否在某个地方遗漏了一个基本原则,或者它是否意味着为了简单地管理音量级别而如此复杂?

                  Have I missed a basic principle somewhere or is it meant to be this convoluted to simply manage volume levels?

                  我无法使用 AVAudioPlayer,因为我需要将 iTunes 曲目加载到播放器中.

                  I cannot use an AVAudioPlayer because I need to load iTunes tracks into the player.

                  推荐答案

                  您可以使用这里描述的方法在播放时改变音量:

                  You can change the volume while playing using the method described here:

                  http://developer.apple.com/library/ios/#qa/qa1716/_index.html

                  虽然文章的文字似乎暗示它只能用于静音,但您实际上可以将音量设置为您喜欢的任何值,并且可以在播放音频后进行设置.例如,假设您的 AVAsset 实例称为asset",您的 AVPlayerItem 实例称为playerItem",而您要设置的音量称为volume",则以下代码应满足您的要求:

                  While the text of the article seems to suggest that it can only be used to mute the audio, you can actually set the volume to anything you like, and you can set it after the audio is playing. For example, assuming your instance of AVAsset is called "asset", your instance of AVPlayerItem is called "playerItem", and the volume you want to set is called "volume", the following code should do what you want:

                  NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
                  
                  NSMutableArray *allAudioParams = [NSMutableArray array];
                  for (AVAssetTrack *track in audioTracks) {
                    AVMutableAudioMixInputParameters *audioInputParams = 
                      [AVMutableAudioMixInputParameters audioMixInputParameters];
                    [audioInputParams setVolume:volume atTime:kCMTimeZero];
                    [audioInputParams setTrackID:[track trackID]];
                    [allAudioParams addObject:audioInputParams];
                  }
                  
                  AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
                  [audioMix setInputParameters:allAudioParams];
                  
                  [playerItem setAudioMix:audioMix];
                  

                  这篇关于调整播放 AVPlayer 的音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Why does Objective-C use YES/NO macro convention instead of true/false?(为什么 Objective-C 使用 YES/NO 宏约定而不是 true/false?)
                  Is there any difference between bool, Boolean, and BOOL in Objective-C?(Objective-C 中的 bool、Boolean 和 BOOL 之间有什么区别吗?)
                  BOOL to NSString(布尔到 NSString)
                  Set bool property of all objects in the array(设置数组中所有对象的布尔属性)
                  Is comparing a BOOL against YES#160;dangerous?(将 BOOL 与 YES 进行比较是否危险?)
                  Objective-C dictionary inserting a BOOL(插入 BOOL 的 Objective-C 字典)
                • <small id='46gix'></small><noframes id='46gix'>

                    <tfoot id='46gix'></tfoot>

                  • <legend id='46gix'><style id='46gix'><dir id='46gix'><q id='46gix'></q></dir></style></legend>
                      <tbody id='46gix'></tbody>

                            <bdo id='46gix'></bdo><ul id='46gix'></ul>
                            <i id='46gix'><tr id='46gix'><dt id='46gix'><q id='46gix'><span id='46gix'><b id='46gix'><form id='46gix'><ins id='46gix'></ins><ul id='46gix'></ul><sub id='46gix'></sub></form><legend id='46gix'></legend><bdo id='46gix'><pre id='46gix'><center id='46gix'></center></pre></bdo></b><th id='46gix'></th></span></q></dt></tr></i><div id='46gix'><tfoot id='46gix'></tfoot><dl id='46gix'><fieldset id='46gix'></fieldset></dl></div>