我想用UISlider来改变音量设置。
我在AVQueuePlayer中使用了AVQueuePlayer。ps0是AVQueuePlayer。
当我使用我的UISlider时,我没有错误和相同的声级
- (IBAction)volumeSliderMoved:(UISlider *)sender
{
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
AVPlayerItem *av = [ps0 currentItem];
CMTime currentTime = [av currentTime];
float volume = [sender value];
[audioInputParams setVolume:volume atTime:currentTime];
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
audioMix.inputParameters = [NSArray arrayWithObject:audioInputParams];
av.audioMix = audioMix;
[ps0 replaceCurrentItemWithPlayerItem: av];
}编辑:我尝试了苹果的另一个解决方案来改变音量设置。
正如您在这个解决方案中所看到的,它创建了一个新的playerItem和一个新的播放器。
但我的playerItem是当前声音的副本,因为我只想更改声音(而不是项目)。它会自动与老玩家相关。
当我试图使用他们的解决方案时。我有一条错误消息说:
AVPlayerItem不能与多个AVPlayer实例关联
有什么建议吗?
再次编辑
用AVQueuePlayer更改回放
我有一个数组,每个mp3名都是“textMissingTab”
我有一个带有AVPlayerItem“soundItems”的数组
创建:
textMissingTab = [[NSArray alloc] initWithObjects:@"cat",@"mouse",@"dog",@"shark",@"dolphin", @"eagle", @"fish", @"wolf", @"rabbit", @"person", @"bird", nil];
for (NSString *text in textMissingTab)
{
NSURL *soundFileURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:text ofType:@"mp3"]];
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:soundFileURL];
[soundItems addObject:item];
}Init :
NSURL *soundFileURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"mp3"]];
ps0 = [[AVQueuePlayer alloc] initWithURL:soundFileURL];Change playItem :文本是NSString
int index = [textMissingTab indexOfObject:text];
[ps0 setActionAtItemEnd:AVPlayerActionAtItemEndNone];
CMTime newTime = CMTimeMake(0, 1);
[ps0 seekToTime:newTime];
[ps0 setRate:1.0f];
[ps0 replaceCurrentItemWithPlayerItem:[soundItems objectAtIndex:(index)]];
[ps0 play];发布于 2013-04-23 17:14:10
我在使用AVQueuePlayer和更改回放参数时遇到了一些问题。如果您的目标是使用滑块进行卷调整,我将用故事板中的空白UISlider替换UIView,然后在该视图中实例化MPVolumeView。这对我来说是可靠的。注意,MPVolumeView没有出现在模拟器上。
发布于 2013-04-24 07:26:01
我想你是对的,提格罗。MPVolumeView是管理健全级别的最佳方法。
在本教程中将解释:http://www.littlereddoor.co.uk/ios/controlling-system-output-volume-by-adding-an-mpvolumeview-object-to-an-ios-application/
“在用户碰到由设备上设置的当前铃声卷创建的绊脚石之前,所有事情都是完全正常工作的。AVAudioPlayer属性的最大值为1.0,其中1.0等于设备当前的铃声音量设置。简单地说,如果设备铃声音量设置为50%,那么100%的AVAudioPlayer卷仍然只能等同于已经设置的50%林格。使用这种方法的局限性说明了这一点。”
我再次编辑了我的帖子,展示了我如何使用AVQueuePlayer管理一些歌曲。这部分代码正在工作。
发布于 2013-11-28 08:26:11
AVAsset *asset;
NSArray *playerTracks;
NSMutableArray *playerParams;
AVMutableAudioMix *muteAudioMix;
for (int k=0; k<[[audio items] count]; k++)
{
//disable audio (this is the version when you have more than one video in the playlist: i write this version so it should be more useful)
asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[soundfile objectAtIndex:k+([soundfile count]-[[audio items] count])] ofType:@"mp3"]] options:nil];
playerTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
playerParams = [NSMutableArray array];
for (AVAssetTrack *track in playerTracks) {
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
[audioInputParams setVolume:1.0 atTime:kCMTimeZero];
[audioInputParams setTrackID:[track trackID]];
[playerParams addObject:audioInputParams];
}
muteAudioMix = [AVMutableAudioMix audioMix];
[muteAudioMix setInputParameters:playerParams];
[[[audio items] objectAtIndex:k] setAudioMix:muteAudioMix];
}https://stackoverflow.com/questions/16170649
复制相似问题