Reputation: 141
Experimenting with creating a simple app to play video on the iPhone (Xcode 7.3, swift iOS9) and I'm just trying to get the player to appear before adding code to load content.
Using storyboard, created a button and segue (show) to an AVViewController object. When app is run on device and button is pressed, I get:
"Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named AVPlayerViewController' "
Prior to declaring my ViewContrller: UIViewController class I have: import UIKit, import AVKit and import AVFoundation. What's missing? I suspect something else I need to import but my research has only turned up AVKit and AVFoundation as necessary.
Upvotes: 3
Views: 1106
Reputation: 750
As @EdDry mentioned above. If you want to use AVPlayerViewController
from storyboard, then follow the steps:
AVKit framework
explicitly to your target.ViewController
with a button. Then add the AVKit Player View Controller
and finally a triguered segue
to show the player controller.ButtonViewController
in my case). Use this url https://download.samplelib.com/mp4/sample-5s.mp4 to load the video.ViewController
.Upvotes: 0
Reputation: 141
I found a solution while viewing answers to other similar problems here on Stack Overflow.
To allow the app to run correctly I had to manually link the frameworks to my project.
In Xcode I clicked on my project's name to get to settings, then added AVFoundation.framework and AVKit.framework in the Linked Frameworks and Libraries section. Now running the app allowed me to instantiate a AVPlayerViewController object without any problems. Apparently, importing AVKit and AVFoundation in my code was not enough. Anyone know why I had to explicitly link the frameworks?
Upvotes: 8