如何播放iPod音乐库中音量与系统音量不同的曲目? [英] How to play tracks from iPod music library with different volume than system volume?

查看:57
本文介绍了如何播放iPod音乐库中音量与系统音量不同的曲目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以与系统音量不同的音量播放ipod音乐库中的音乐(如用户定义的播放列表等)?

How can I play music from the ipod music library (like user-defined playlists, etc.) at a different volume than the system volume?

推荐答案

实际上,我发现

Actually I found a really easy way to do this by loading iPod URL's from MPMusicPlayer, but then doing playback through AVAudioPlayer.

// Get-da iTunes player thing
MPMusicPlayerController* iTunes = [MPMusicPlayerController iPodMusicPlayer]; 

// whazzong
MPMediaItem *currentSong = [iTunes nowPlayingItem];

// whazzurl
NSURL *currentSongURL = [currentSong valueForProperty:MPMediaItemPropertyAssetURL];

info( "AVAudioPlayer playing %s", [currentSongURL.absoluteString UTF8String] ) ;

// mamme AVAudioPlayer
NSError *err;
avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:currentSongURL error:&err] ;
if( err!=nil )
{
  error( "AVAudioPlayer couldn't load %s", [currentSongURL.absoluteString UTF8String] ) ;
}
avAudioPlayer.numberOfLoops = -1; //infinite

// Play that t
[avAudioPlayer prepareToPlay] ;
[avAudioPlayer play];

[avAudioPlayer setVolume:0.5]; // set the AVAUDIO PLAYER's volume to only 50%. This
// does NOT affect system volume. You can adjust this music volume anywhere else too.

这篇关于如何播放iPod音乐库中音量与系统音量不同的曲目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆