Xcode 如何在服务器上远程播放mp3文件而不阻塞ios中的UI
我正在使用iOS应用程序,让我从url播放mp3文件。一旦加载,它就可以正常工作。问题是加载大约需要30秒,并且会阻止UI转换到其他视图控制器。 代码: 我正在使用AVAudioPlayer类,以下是我的设置Xcode 如何在服务器上远程播放mp3文件而不阻塞ios中的UI,xcode,url,ios8,avaudioplayer,Xcode,Url,Ios8,Avaudioplayer,我正在使用iOS应用程序,让我从url播放mp3文件。一旦加载,它就可以正常工作。问题是加载大约需要30秒,并且会阻止UI转换到其他视图控制器。 代码: 我正在使用AVAudioPlayer类,以下是我的设置 (void)setupAudioPlayer:(NSString*)fName { // calls and pass url name to MyAudioPlayer class method [self.audioPlayer initWithD
(void)setupAudioPlayer:(NSString*)fName
{
// calls and pass url name to MyAudioPlayer class method
[self.audioPlayer initWithData:fName];
self.currentTimeSlider.maximumValue =
[self.audioPlayer getAudioDuration];
//init the current time display and the labels.
//if a current time was stored
//for this player then take it and update the time display
self.timeElapsed.text = @"0:00";
self.duration.text = [NSString stringWithFormat:@"-%@",
[self.audioPlayer timeFormat:
[self.audioPlayer getAudioDuration]]];
}
- 然后调用上述方法并将url作为“”传递
谢谢以下是我的远程mp3文件流式播放代码:
@import AVFoundation;
...
@property (nonatomic, retain) AVPlayer *objAVPlayer;
@property (nonatomic, getter=isPlaying) BOOL playing;
// in viewDidLoad
_objAVPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://www.asdasd.com/file.mp3"]];
...
- (void)playPressed {
if([self isPlaying]) {
_playing = false;
[_objAVPlayer pause];
} else {
_playing = true;
[_objAVPlayer play];
}
}
可能的时间延迟可能是由于连接缓慢造成的。我希望这能帮助你
@import AVFoundation;
...
@property (nonatomic, retain) AVPlayer *objAVPlayer;
@property (nonatomic, getter=isPlaying) BOOL playing;
// in viewDidLoad
_objAVPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://www.asdasd.com/file.mp3"]];
...
- (void)playPressed {
if([self isPlaying]) {
_playing = false;
[_objAVPlayer pause];
} else {
_playing = true;
[_objAVPlayer play];
}
}