2017-12-07 4 views
0

우리는 사용자가 비디오 및 이미지를 서버에 업로드 할 수있는 앱을 가지고 있습니다. 안드로이드에서 mp4 비디오를 업로드하면 ios 장치에서 재생되지 않습니다. 이것은 내 코드입니다. 플레이어 상태가 readytoplay로 표시되지만로드되지 않고 오류가 발생하지 않습니다. vieo는 웹과 안드로이드로 잘 돌아가고 있습니다. 이 같은안드로이드에서 업로드 된 mp4 비디오는 ios에서 재생되지 않습니다.

헤더 파일 :이 같은

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController 

@property (weak, nonatomic) IBOutlet UIView *playerView; 

@end 

실행 파일 : https://justgolive.net/assets/uploads/newrecordings/20919/19777983355a28e15326df6.mp4

NSURL *streamURL = [NSURL URLWithString:_videoUrl]; 
    player = [AVPlayer playerWithURL:streamURL]; 

    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; 
    playerLayer.frame =self.previewView.frame; 
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
    //CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height/1.2); 
    [self.previewView.layer addSublayer:playerLayer]; 

    // [self.playerContainer setUserInteractionEnabled:NO]; //to avoid touch events when activity is on 
    [self.player addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL]; 
    player.actionAtItemEnd = AVPlayerActionAtItemEndNone; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(playerItemDidReachEnd:) 
               name:AVPlayerItemDidPlayToEndTimeNotification 
               object:[player currentItem]]; 
+0

플레이어의 play 메소드를 호출 했습니까? –

+0

예, [player play]를 추가했습니다. – Logic

답변

1

내가 당신의 비디오의 URL을 아래 코드 작업으로 시도 : 여기 이 동영상 URL입니다

#import "ViewController.h" 
#import <AVFoundation/AVFoundation.h> 

@interface ViewController() 
@property (nonatomic) AVPlayer *player; 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 




    NSURL *url = [NSURL URLWithString:@"https://justgolive.net/assets/uploads/newrecordings/20919/19777983355a28e15326df6.mp4"]; 

    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url]; 

    self.player = [AVPlayer playerWithPlayerItem:playerItem]; 

    CALayer *superlayer = self.playerView.layer; 
    self.player.volume = 20.0; 

    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player]; 
    [playerLayer setFrame:self.playerView.bounds]; 
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspect; 
    playerLayer.frame = self.playerView.layer.bounds; 
    [superlayer addSublayer:playerLayer]; 
    [self.player seekToTime:kCMTimeZero]; 
    [self.player play]; 


} 


- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


@end 
+0

확인. 내가 시험해 보자 – Logic

+0

그게 작동하지 않습니다. 프로젝트 파일을 공유 할 수 있습니까? idid 똑같은 일을 하루에 100 번하고 재생하지 못했습니다. – Logic

+0

내 수정 된 답변에서 앱을 실행 한 후 출력을 찾아주세요. Android에서 가져온 URL은 동영상입니까? –

관련 문제