5
我正在嘗試爲iPhone應用程序流式傳輸音頻。藉助AVPlayer,我可以通過幾行代碼從URL流式傳輸音頻。儘管如此,我仍然無法使用AVPlayer更改音量。任何幫助,將不勝感激。如何從iPhone的應用程序的URL流式傳輸音頻並使用AVPlayer更改音量?
我正在嘗試爲iPhone應用程序流式傳輸音頻。藉助AVPlayer,我可以通過幾行代碼從URL流式傳輸音頻。儘管如此,我仍然無法使用AVPlayer更改音量。任何幫助,將不勝感激。如何從iPhone的應用程序的URL流式傳輸音頻並使用AVPlayer更改音量?
您可以通過屬性volume改變音量,請參閱下面的代碼
NSString* resourcePath = url; //your url
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 5.0f; //set volume here
[audioPlayer prepareToPlay];
我想流音頻的應用程序,而不是從一個文件。因此,我無法使用AVAudioPlayer。 – user1530580 2013-02-25 04:27:45
是的,你可以傳遞url到_objectData就像這樣NSData * _objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:「http://a40.phobos.apple.com/us/r1000/062/Music/ec/88/d0/ mzm.fqrwrunh.aac.p.m4a「]]; – 2013-02-25 06:02:40
這是一個實況流(電臺),而不是從其他地方流式傳輸音樂文件。它不適用於實時連續流等情況。 – user1530580 2013-02-25 15:54:03