从android上传的mp4视频不能在ios上播放

时间:2017-12-07 11:40:13

标签: objective-c avplayer

我们有一个应用程序,允许用户将视频和图像上传到服务器。 如果我从Android上传一个mp4视频,它不会在ios设备上播放。 这是我的代码。播放器状态显示readytoplay但它没有加载并且没有出现错误。 vieo在网络和Android上都很好玩。  这是视频网址: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]];

1 个答案:

答案 0 :(得分:1)

我已尝试使用您的视频网址并使用以下代码:

像这样的

头文件:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

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

@end

这样的实施文件:

#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