我正在尝试从我的应用程序中的 URL 播放音频。在 iOS 8(模拟器和物理设备)中,一切都按预期进行。对于 iOS 9,它可以在模拟器中运行,但在设备上,音频根本无法播放。出现流媒体,如果我点击播放,进度条还会显示音频正在加载和播放,但声音没有出现。此问题发生在 iOS 9 物理设备中。它完全适用于 iOS 8 物理设备。
我创建了一个简单的按钮。单击按钮时,将加载 AVPlayerViewController 并使用给定的 URL 初始化 AVPlayer。代码如下:
#import "ViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playAudio:(id)sender {
NSURL *url = [NSURL URLWithString:@"https://path/to/my.mp3"];
[self performSegueWithIdentifier:@"playSegue" sender:url];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
AVPlayerViewController *viewController = (AVPlayerViewController *)segue.destinationViewController;
viewController.player = [AVPlayer playerWithURL:(NSURL *)sender];
}
@end