我有一個從服務器到AVPlayer播放視頻文件,但我也有使用基本身份驗證玩這個file.here是我的代碼如何使用AVPlayer進行基本認證從服務器播放視頻文件?
NSMutableDictionary * headers = [NSMutableDictionary dictionary];
NSData *basicAuthCredentials = [[NSString stringWithFormat:@"username:password"] dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64AuthCredentials = [basicAuthCredentials base64EncodedStringWithOptions:(NSDataBase64EncodingOptions)0];
[headers setValue:[NSString stringWithFormat:@"Basic %@", base64AuthCredentials] forKey:@"Authorization"];
NSURL *videoURL = [NSURL URLWithString:fileUrlString];
AVURLAsset * asset = [AVURLAsset URLAssetWithURL:videoURL options:headers];
AVPlayerItem * item = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:item];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
playerViewController.delegate = (id)self;
[player play];
[self presentViewController:playerViewController animated:YES completion:nil];
會發生什麼? – Droppy
AVPlayerViewController成功提交,但文件未播放。 –
服務器是否收到請求?你看過哪些錯誤報告可用嗎? – Droppy