7

I'm having some trouble playing video content on both an ios device and in the simulator.

Goal: Stream a video from an online resource given here: public video streams using hls using the AVPlayerViewController, just to learn how it works.

This consistently resulted in no errors being thrown, but the view controller presenting me with this view.

AvPlayerViewController

I decided to step back and test on a local resource, so I filmed a short screen capture in quicktime (.m4v) and saved it right to the project. This resulted in the exact same behavior with no errors reported.

Here is the code (AVKit and AVFoundation are imported ):

var playerVC : AVPlayerViewController!
var playerItem : AVPlayerItem!
var player : AVPlayer!
var playerLayer: AVPlayerLayer!

override func viewDidAppear(animated: Bool) {

    let bundle = NSBundle.mainBundle()
    let path = bundle.pathForResource("testVideos", ofType: "m4v")
    let url = NSURL.init(string: path!)

    playerItem = AVPlayerItem.init(URL: url!)
    player = AVPlayer.init(playerItem: playerItem)
    playerVC = AVPlayerViewController.init();
    playerVC.player = player;

    self.presentViewController(playerVC, animated: true) { () -> Void in
        self.playerVC.player?.play()
    }
}

Seeing this warning when building to an IpadMini 4: <CATransformLayer: 0x136ea1030> - changing property masksToBounds in transform-only layer, will have no effect

Xcode: Version 7.1 Targeting: iOS 9.0

Update Just some nasty constraint output from the AVPlayerViewController. I don't think this is contributing, but here it is:

2015-10-28 15:12:02.777 AVKitTest[4441:94545] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "", "", "", "", "", "", "", "" )

Community
  • 1
  • 1
CostelloNicho
  • 704
  • 1
  • 9
  • 20

3 Answers3

5

Turns out it was something silly, just had to change:

let url = NSURL.init(string: path!) playerItem = AVPlayerItem.init(URL: url!)

with:

let url = NSURL.init(fileURLWithPath: path!) let playerItem = AVPlayerItem.init(URL: url)

CostelloNicho
  • 704
  • 1
  • 9
  • 20
0

It looks like you're not properly setting up AVPlayerLayer.

Look at the docs for AVPlayerLayer: "Returns an instance of AVPlayerLayer to display the visual output of the specified AVPlayer."

example hierarchy from the AVFoundation Programming Guide

JAL
  • 41,701
  • 23
  • 172
  • 300
suite22
  • 476
  • 3
  • 16
  • Thanks for the post, you are 100% right if I were trying to set up and manage my own AVplayer but AVPlayerViewController is a part of AVKit that is supposed to manage all aspects of the player out of the box. – CostelloNicho Oct 28 '15 at 19:57
0

This error means that there is not a video found in the supplied url. If you're using PHPickerViewController to load videos from the library you have to copy the files to a temporary disk location before playing them. See this thread for more context.