Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Play video with different source type #27

Open
kevinbubu opened this issue Nov 30, 2015 · 2 comments
Open

Play video with different source type #27

kevinbubu opened this issue Nov 30, 2015 · 2 comments

Comments

@kevinbubu
Copy link

Hi,

I try to play video with different source type, but the second source can't be played.

First source type is mp4, and second source type is m3u8. It's work smoothly on iOS 9 device and simulator, but it can't work on iOS 7 & 8. How can I do?

Error Log:

didFailWithError: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x174467dc0 {NSUnderlyingError=0x17005eea0 "The operation couldn’t be completed. (OSStatus error -12783.)", NSLocalizedFailureReason=An unknown error occurred (-12783), NSLocalizedDescription=The operation could not be completed}

My code:

  • (void)setupVideoPlayer
    {
    self.videoPlayerView = [[VIMVideoPlayerView alloc] init];
    [self.videoPlayerView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.videoPlayerView setVideoFillMode:AVLayerVideoGravityResizeAspect];
    [self.videoPlayerView setDelegate:self];
    [self.videoPlayerView setBackgroundColor:[UIColor redColor]];
    [self.view insertSubview:self.videoPlayerView atIndex:0];

    NSURL *URL = [NSURL URLWithString:@"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"]; // https://secure-c.vimeocdn.com/p/video/yosemite_hd_ii_hd.mp4"];
    [self.videoPlayerView.player setDelegate:self];
    [self.videoPlayerView.player enableTimeUpdates];
    [self.videoPlayerView.player enableAirplay];
    [self.videoPlayerView.player setMuted:NO];
    [self.videoPlayerView.player setLooping:NO];
    [self.videoPlayerView.player setURL:URL];
    [self.videoPlayerView.player play];
    }

  • (void)changeSourceButtonClick
    {
    [self.videoPlayerView.player reset];
    [self.videoPlayerView.player setURL:[NSURL URLWithString:@"http://v.jxvdy.com/sendfile/w5bgP3A8JgiQQo5l0hvoNGE2H16WbN09X-ONHPq3P3C1BISgf7C-qVs6_c8oaw3zKScO78I--b0BGFBRxlpw13sf2e54QA"]];
    [self.videoPlayerView.player play];
    }

Thanks!

@alfiehanssen
Copy link
Contributor

@kevinbubu I'm fairly certain that this is a bug in AVPlayer. Playing 2 consecutive videos with the same AVPlayer, each a different type, the second one will fail to play:

http://stackoverflow.com/questions/10839061/avplayer-not-switching-between-progressive-download-and-streaming

@kevinbubu
Copy link
Author

@alfiehanssen Thank you for your reply. But I can use AVPlayer and play smoothly. Is it VIMVideoPlayer's bug?

This is my code:


  • (void)viewDidLoad
    {
    [super viewDidLoad];

    sourceIndex = 0;

    NSURL *videoUrl = [NSURL URLWithString:@"http://v.jxvdy.com/sendfile/w5bgP3A8JgiQQo5l0hvoNGE2H16WbN09X-ONHPq3P3C1BISgf7C-qVs6_c8oaw3zKScO78I--b0BGFBRxlpw13sf2e54QA"];
    self.playerItem = [AVPlayerItem playerItemWithURL:videoUrl];
    [self.playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    [self.playerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];

    self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
    self.playerView.player = _player;

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(moviePlayDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:_playerItem];

    UIButton *changeSource = [UIButton buttonWithType:UIButtonTypeCustom];
    [changeSource setTranslatesAutoresizingMaskIntoConstraints:NO];
    [changeSource setFrame:CGRectMake(10, 20, 60, 40)];
    [changeSource setTitle:@"Change" forState:UIControlStateNormal];
    [changeSource setTitleColor: [UIColor blackColor] forState: UIControlStateNormal];
    [changeSource setBackgroundColor:[UIColor blueColor]];
    [changeSource addTarget:self action:@selector(changeSource) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:changeSource];
    }

  • (void)changeSource
    {
    NSArray *sourceArray = [NSArray arrayWithObjects:@"http://v.jxvdy.com/sendfile/w5bgP3A8JgiQQo5l0hvoNGE2H16WbN09X-ONHPq3P3C1BISgf7C-qVs6_c8oaw3zKScO78I--b0BGFBRxlpw13sf2e54QA", @"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8", @"https://secure-c.vimeocdn.com/p/video/yosemite_hd_ii_hd.mp4", nil];

    [self.player pause];

    // reset

    [self.playerItem cancelPendingSeeks];
    [self.playerItem removeObserver:self forKeyPath:@"status" context:nil];
    [self.playerItem removeObserver:self forKeyPath:@"loadedTimeRanges" context:nil];
    [self.playerView.player removeTimeObserver:self.playbackTimeObserver];

    [self.player replaceCurrentItemWithPlayerItem:nil];
    self.playerItem = nil;

    // init
    NSURL *videoUrl = [NSURL URLWithString:[sourceArray objectAtIndex:sourceIndex]];
    self.playerItem = [AVPlayerItem playerItemWithURL:videoUrl];
    [self.playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    [self.playerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];

    self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
    self.playerView.player = _player;
    self.stateButton.enabled = NO;

    sourceIndex++;
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants