ios - 使用 AVAudioPlayer 从 URL 播放音频
<p><p>我正在从下面给出的 URL 播放音频</p>
<p>"<a href="http://sumeetmusiclocal.wsisites.net/Songs/Kashyala" rel="noreferrer noopener nofollow">http://sumeetmusiclocal.wsisites.net/Songs/Kashyala</a> Lavato (Lavani).mp3"</p>
<p>通过使用下面给出的代码</p>
<pre><code>NSString *urlString = @"http://sumeetmusiclocal.wsisites.net/Songs/Kashyala Lavato (Lavani).mp3";
NSURL *audioFileLocationURL = ];
NSError *error;
audioPlayer = [ initWithContentsOfURL:audioFileLocationURL error:&error];
;
if (error) {
NSLog(@"%@", );
[ setEnabled:NO];
[ setEnabled:NO];
[ setText:@"Unable to load file"];
[ setHidden:NO];
} else {
[ setText:];
[ setHidden:NO];
//Make sure the system follows our playback status
[ setCategory:AVAudioSessionCategoryPlayback error:nil];
[ setActive: YES error: nil];
//Load the audio into memory
;
}
</code></pre>
<p>但我收到错误提示</p>
<pre><code>Printing description of error:
Error Domain=NSOSStatusErrorDomain Code=2003334207 "(null)"
2016-03-08 12:43:45.835 SumeetApp The operation couldn’t be completed. (OSStatus error 2003334207.)
</code></pre>
<p>谁能帮我解决这个错误或建议我用其他方法从 url 播放音频。</p>
<p>谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个</p>
<pre><code>AVURLAsset *asset = ];
AVPlayerItem *playerItem1 = ;
AVPlayer *player1 = ;
AVPlayerLayer *playerLayer1 = ;
playerLayer1.videoGravity = AVLayerVideoGravityResizeAspectFill;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
playerLayer1.frame = self.view.frame;
});
;
;
</code></pre>
<p>希望这对你有用。</p></p>
<p style="font-size: 20px;">关于ios - 使用 AVAudioPlayer 从 URL 播放音频,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35861310/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35861310/
</a>
</p>
页:
[1]