我試圖從我的應用程序中的URL播放音頻。一切都如預期在iOS 8(模擬器和物理設備)中發生。對於iOS 9,它可以在模擬器中工作,但在設備上,音頻根本無法播放。流媒體出現後,如果我點擊播放,進度條也顯示音頻正在加載並播放,但聲音不會來。這個問題發生在iOS 9物理設備上。它適用於iOS 8物理設備。AVPlayer不播放音頻 - iOS 9,目標 - C
我創建了一個簡單的按鈕。點擊按鈕時,AVPlayerViewController被加載,並且AVPlayer使用給定的URL進行初始化。代碼如下:
#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
是url零在你準備SEGUE? –
不,我做了NSLog(「%@」,(NSURL *)sender),它給了我日誌中的URL。 –