2016-09-30 22 views
0

내 m3u8 스트리밍에 대한 아이폰과 ipad 장치에 완벽하게 작동하지만 내가 AirPlay를 통해 애플 TV에서 그 스트리밍을 재생하려고 할 때 AVPlayer를 사용하고 있습니다. AppleTv 다음과 같이 :m3u8 스트리밍 애플 티비 (airplay)에서 작동하지 않습니다

NSURL * url = [NSURL URLWithString : @ "// m3u8 path here"]; AVPlayerItem * playerItem = [AVPlayerItem playerItemWithURL : url];

self.videoPlayer = [AVPlayer playerWithPlayerItem:playerItem]; 
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.videoPlayer]; 
[self.playerLayer setFrame:self.view.frame]; 
[self.view.layer addSublayer:self.playerLayer]; 
[self.videoPlayer play]; 
[self.videoPlayer setAllowsExternalPlayback:YES]; 
self.videoPlayer.usesExternalPlaybackWhileExternalScreenIsActive = YES; 

애플 TV에 내 모바일을 연결 한 후 나는 다음 위의 코드와 애플 TV 시작 로딩을 실행하고로드가 완료 후에 내가 내 TV에 스트리밍의 첫 번째 사진을 본 후 갇혀에게 내가 모르는 그 중지 할 수 있습니다 왜 그것의 붙어 나는 다른 많은 m3u8 링크를 시도하지만 사과의 TV에 붙어있는 모든 링크, 그래서 아무도 도와 줄 수 있고 어디가 잘못 가고 있는지 ..... 감사합니다

답변

0

나는 mosu 스트림을 ios에서 재생할 수 있습니다. 여기

샘플 코드 :이 유용합니다

@property (weak, nonatomic) IBOutlet UIView *playerView; 
@property (nonatomic, strong) AVURLAsset *asset; 
@property (nonatomic, strong) AVPlayer *player; 
@property (nonatomic, strong) AVPlayerItem *playerItem; 

- (IBAction)startStopForwardingVideo:(id)sender 
{ 
    _asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:@"http://******sl.m3u8 live stream url"] options:nil]; 
    NSError *error = nil; 
    self.playerItem = [AVPlayerItem playerItemWithAsset:_asset]; 
    [self.player addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:AVPlayerItemStatusContext]; 

    self.player = [[AVPlayer alloc] initWithPlayerItem:self.playerItem]; 
    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player]; 

    playerLayer.frame = CGRectMake(0, 0, self.playerView.frame.size.width, self.playerView.frame.size.height); 
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
    [_playerView.layer addSublayer:playerLayer]; 
} 

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 
{ 
    if ([keyPath isEqualToString:@“status”]) { 

      AVPlayerStatus status = [change[NSKeyValueChangeNewKey] integerValue]; 
      switch (status) { 
       case AVPlayerItemStatusUnknown: 
        break; 
       case AVPlayerItemStatusReadyToPlay: 
       { 
        [self.player play]; 
       } 
      break; 
     case AVPlayerItemStatusFailed: 
      [self stopLoadingAnimationAndHandleError:[[self.player currentItem] error]]; 
      break; 
      } 
    } 
} 

희망

+0

내가 AirPlay를 사용할 때 애플 TV가 작동하지에 애플 TV에 대해 이야기하고 iOS에서의 작업 @Punita –