AVFoundation을 사용하여 로컬 비디오를 재생하려고합니다. 나는 웹에서 비디오를 재생 한 다음 작동하는 로컬 비디오를 재생할 때만 여기서 무슨 일이 일어나는지 알지 못합니다. 방금 로컬 비디오를 재생하면 오류가납니다.로컬 비디오는 전에 웹 비디오를 재생할 때만 재생됩니다 - AVFoundation
항목을 재생할 수 없습니다. 자산 트랙이로드되었지만 재생할 수 없었습니다.
임 여기에 파일 : /// VAR/모바일/용기/데이터/응용 프로그램/E806EC2A-2C5D-
- (void)setURL:(NSURL*)URL
{
if (mURL != URL)
{
[mURL release];
mURL = [URL copy];
NSLog(@"Im here %@",mURL);
}
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:mURL options:nil];
NSArray *requestedKeys = [NSArray arrayWithObjects:kTracksKey, kPlayableKey, nil];
/* Tells the asset to load the values of any of the specified keys that are not already loaded. */
[asset loadValuesAsynchronouslyForKeys:requestedKeys completionHandler:
^{
dispatch_async(dispatch_get_main_queue(),
^{
/* IMPORTANT: Must dispatch to main queue in order to operate on the AVPlayer and AVPlayerItem. */
[self prepareToPlayAsset:asset withKeys:requestedKeys];
});
}];
}
- (void)prepareToPlayAsset:(AVURLAsset *)asset withKeys:(NSArray *)requestedKeys
{
if (!asset.playable)
{
NSString *localizedDescription = NSLocalizedString(@"Item cannot be played", @"Item cannot be played description");
NSString *localizedFailureReason = NSLocalizedString(@"The assets tracks were loaded, but could not be made playable.", @"Item cannot be played failure reason");
NSDictionary *errorDict = [NSDictionary dictionaryWithObjectsAndKeys:
localizedDescription, NSLocalizedDescriptionKey,
localizedFailureReason, NSLocalizedFailureReasonErrorKey,
nil];
NSError *assetCannotBePlayedError = [NSError errorWithDomain:@"StitchedStreamPlayer" code:0 userInfo:errorDict];
[self assetFailedToPrepareForPlayback:assetCannotBePlayedError];
return;
}
if (self.mPlayerItem)
{
[self.mPlayerItem removeObserver:self forKeyPath:kStatusKey];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.mPlayerItem];
}
self.mPlayerItem = [AVPlayerItem playerItemWithAsset:asset];
[self.mPlayerItem addObserver:self
forKeyPath:kStatusKey
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AVPlayerDemoPlaybackViewControllerStatusObservationContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.mPlayerItem];
seekToZeroBeforePlay = NO;
if (!self.mPlayer)
{
[self setPlayer:[AVPlayer playerWithPlayerItem:self.mPlayerItem]];
[self.player addObserver:self
forKeyPath:kCurrentItemKey
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AVPlayerDemoPlaybackViewControllerCurrentItemObservationContext];
[self.player addObserver:self
forKeyPath:kRateKey
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AVPlayerDemoPlaybackViewControllerRateObservationContext];
}
if (self.player.currentItem != self.mPlayerItem)
{
[self.mPlayer replaceCurrentItemWithPlayerItem:self.mPlayerItem];
[self syncPlayPauseButtons];
}
[self.mScrubber setValue:0.0];
[self play:nil];
loading.hidden = YES;
}
NSLog 사용 메신저 로컬 URL을 제공합니다
그리고 여기 내 코드입니다 4B86-AD05-D9FD29E8FDDD/문서/다운로드/VVV % 20- % 20 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % 20 % m4v
미리 감사드립니다.
가 작동하지 않습니다와 내가 AvFoundation를 사용하려면 MediaPlayer.framework (# import를) 추가합니다. 그건 그렇고, 고마워요 대답에 대한 많은 :) –