Logic
Logic

Reputation: 705

mp4 video uploaded from android not play on ios

We have an app that allows user to upload videos and images to server. if i upload a mp4 video from android , it is not playing in ios devices. this is my code. player status shows up readytoplay but it doesn't load up and no error comes up. vieo is playing fine with web and android. here is video url : 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]];

Upvotes: 0

Views: 500

Answers (1)

Mangesh Murhe
Mangesh Murhe

Reputation: 361

I have tried with your url of Video and working with below code:

header file like this:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

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

@end

Implementation file like this:

#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

Upvotes: 1

Related Questions