Updating to xCode9 and Swift 4 for videos

In xcode 8 with swift 3 my app would show a series of video segments that were identified by Bundle.main.url(forResource: video name, withExtension:mov)


But now, in xCode 9 with Swift 4, it chokes saying "Invalid asset name supplied: '(null)'", even though I supplied that name when setting up the URL. How should I approach correcting this? It seems to me the video names should be in the Bundle, but how do I use them. Or should I not approach it as a series of URLs ?


I can't seem to find the proper syntax to replace AVPlayerItem(url: preUrl!) if I should redo my approach to controlling the video segments. Any suggestions ?


Thank you ... Eric

Replies

You need to split this problem up into two:

  • Is the issue getting the URL to your bundled video?

  • Or it is with playing such a URL?

I suggest you start with the first point: is the URL itself value? You should check that the value you got back

url(forResource:withExtension:)
is not nil. You should then check that the file exists on disk. A good thing to get here is the file size. Get the size like this:
let fileSize = try! u.resourceValues(forKeys: [.fileSizeKey]).fileSize!
print(fileSize)

and then compare to what you expect.

IMPORTANT The above snippet is for debugging and it’s probably a bad idea to use it in production code. Specifically, if something goes wrong the code will crash, which is actually a good thing while debugging.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I have discovered what I think is happening, but I need to find out what to do about it. My App plays a series of short videos while adding a lot of text to them while they play. It worked in version 8 before I moved to 9, with IOS 11. The first message I get is a WARNING "AVF context unavailable for sharedAudioPresentationContext ". The videos may or may not include audio. In other words all of the other messages could be happening because it's not letting me merge the video with the text, even if the audio is silent.


What approach can I take that is allowed in xCode 9 to merge the video segments with the constantly changing text of my App ? Thanks for your help !

I can actually see the videos, until the app tries to merge the text, at which time the movie stays on the screen but makes no further progress, although I can see the slight motion of attempted repeated progress and then immediate fallback.

THIS IS A DESCRIPTION OF A PROBLEM IN BUILDING A QUEUE OF VIDEO CLIPS WHICH ARE THEN THEN PLAYED IN SEQUENCE BY THE QUEUE PLAYER

let assetKeys = ["playable"]

A SERIES OF MOVIE CLIPS ARE PROGRAMMATICALLY SELECTED AND ADDED TO THE “playerItem” ARRAY USING THE LOGIC BELOW REPEATEDLY BELOW TO BUILD UP THE MOVIE CLIP SEQUENCE WITH DIFFERENT CLIP TITLES AND SUFFIX LETTERS

url = Bundle.main.url(forResource: movieToPlay.clipTitle + "C", withExtension: "mov")

asset = AVAsset(url: url!)

playerItem = AVPlayerItem(asset: asset, automaticallyLoadedAssetKeys: assetKeys)

self.versesToSing = [playerItem!]

(FOR THE INITIAL CLIP IT SAYS self.versesToSing = [playerItem!], OF COURSE)

WHEN ALL THE CLIPS HAVE BEEN ADDED THE FOLLOWING LOGIC IS USED TO PLAY THE MOVIE CLIPS IN SEQUENCE

self.myQueue = AVQueuePlayer.init(items: self.moviesToPlay!)

self.myPlayer = self.myQueue

let controller=AVPlayerViewController()

controller.player=self.myPlayer

controller.view.frame = self.view.frame

self.view.addSubview(controller.view)

self.addChildViewController(controller)

self.myPlayer!.play()

RESULT: I CAN SEE THE MOVIECLIPS IN THE SEQUENCE DESIRED, IN FACT I CAN EVEN HEAR THEIR AUDIT BUT JUST BARELY, BUT I HAVE TO HIT THE PLAY BUTTON THREE OR FOUR TIMES, WHICH MEANS SOMETHING SOMEWHERE IS NOT RIGHT, AND I GET THE WARNING/ERROR MESSAGES BELOW. THIS SUGGESTS TO ME THAT MY asset = AVAsset(url: url!) IS NOT THE RIGHT STATEMENT FOR THE JOB. I TRIED USING asset = AVURLAsset(url: url!) BUT THAT DIDN”T CHANGE ANYTHING.

ANY SUGGESTIONS, PLEASE, PLEASE ? THANK YOU. I THINK THAT THE NAMES OF THE MOVIE CLIPS ISN'T GETTING TO THE QUEUE, AND HENCE HE PLAYER, BUT I DON"T KNOW WHAT TO DO ABOUT IT, BUT IT COULD BE SOMETHING ELSE, OF COURSE.

Resulting Warning messages are below:

2017-10-18 16:11:40.159245-0400 SongBook 10[49287:19067958] [MediaRemote] [AVOutputContext] WARNING: AVF context unavailable for sharedAudioPresentationContext

2017-10-18 16:11:40.380376-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.382687-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.398269-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.400804-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.571747-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.571958-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:12:33.305206-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:12:33.305438-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:12:33.307880-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:12:33.308053-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

THIS IS A CORRECTION TO MY PREVIOUS DRAFT



THIS IS A DESCRIPTION OF A PROBLEM IN BUILDING A QUEUE OF VIDEO CLIPS WHICH ARE THEN THEN PLAYED IN SEQUENCE BY THE QUEUE PLAYER

let assetKeys = ["playable"]

A SERIES OF MOVIE CLIPS ARE PROGRAMMATICALLY SELECTED AND ADDED TO THE “playerItem” ARRAY USING THE LOGIC BELOW REPEATEDLY BELOW

TO BUILD UP THE MOVIE CLIP SEQUENCE WITH DIFFERENT CLIP TITLES AND SUFFIX LETTERS

url = Bundle.main.url(forResource: movieToPlay.clipTitle + "C", withExtension: "mov")

asset = AVAsset(url: url!)

playerItem = AVPlayerItem(asset: asset, automaticallyLoadedAssetKeys: assetKeys)

self.moviesToPlay = Self.moviesToPlay + [playerItem!]

(FOR THE INITIAL CLIP IT SAYS self.moviesToPlay = [playerItem!], OF COURSE)

WHEN ALL THE CLIPS HAVE BEEN ADDED THE FOLLOWING LOGIC IS USED TO PLAY THE MOVIE CLIPS IN SEQUENCE

self.myQueue = AVQueuePlayer.init(items: self.moviesToPlay!)

self.myPlayer = self.myQueue

let controller=AVPlayerViewController()

controller.player=self.myPlayer

controller.view.frame = self.view.frame

self.view.addSubview(controller.view)

self.addChildViewController(controller)

self.myPlayer!.play()


RESULT: I CAN SEE THE MOVIECLIPS IN THE SEQUENCE DESIRED, IN FACT I CAN EVEN HEAR THEIR AUDIT BUT JUST BARELY, BUT I HAVE TO HIT THE PLAY

BUTTON THREE OR FOUR TIMES, WHICH MEANS SOMETHING SOMEWHERE IS NOT RIGHT, AND I GET THE WARNING/ERROR MESSAGES BELOW. THIS SUGGESTS TO ME THAT MY

asset = AVAsset(url: url!) IS NOT THE RIGHT STATEMENT FOR THE JOB. I TRIED USING asset = AVURLAsset(url: url!) BUT THAT DIDN”T CHANGE ANYTHING.

ANY SUGGESTIONS, PLEASE, PLEASE ? THANK YOU.

Resulting Warning messages:

2017-10-18 16:11:40.159245-0400 SongBook 10[49287:19067958] [MediaRemote] [AVOutputContext] WARNING: AVF context unavailable for sharedAudioPresentationContext

2017-10-18 16:11:40.380376-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.382687-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.398269-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.400804-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.571747-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:11:40.571958-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:12:33.305206-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:12:33.305438-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:12:33.307880-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

2017-10-18 16:12:33.308053-0400 SongBook 10[49287:19067958] [framework] CUICatalog: Invalid asset name supplied: '(null)'

THIS IS A DESCRIPTION OF A PROBLEM …

Is there a reason you’re shouting all of this? Also, it would help if you formatted your code snippets as code (using the

<>
button in the editor).

I can see the movieclips in the sequence desired, in fact i can even hear their audit but just barely, but i have to hit the play button three or four times …

So it sounds like your URL issue is resolved and now you have an AVPlayer problem. I’m going to recommend that you ask that over in Media > AVFoundation (Video and Camera), where you’re more likely to connect with folks with AVFoundation experience.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"