coolmanbat1
coolmanbat1

Reputation: 23

NSString pathway always returns nil despite having the file contained in the folder

So i'm trying to create a video screen saver for macOS 10.12 by using NSString to obtain the pathway, and NSURL to store the pathway.

However every time I test the screen saver, it crashes with this error:

Application Specific Information:
com.apple.preference.desktopscreeneffect v.5.1 (Desktop & Screen Saver)
Crashing on exception: *** -[NSURL initFileURLWithPath:]: nil string parameter

I believe the problem lies here:

// Create the video path then use it. (Problem at the moment: the pathway always returns nil)
NSString *screenSaverPath = [[NSBundle mainBundle] pathForResource:@"apple" ofType:@"mp4"];
NSURL *screenSaver = [NSURL fileURLWithPath:screenSaverPath];

//Obtain the size of the screen.
NSSize size = [self bounds].size;

//Draw the video player.
AVPlayer *video = [AVPlayer playerWithURL:screenSaver];

But I am unsure as to how I can tackle this problem. Does anyone know any way as to how you can resolve this problem? Thank you!

Upvotes: 1

Views: 50

Answers (1)

uliwitness
uliwitness

Reputation: 8793

Screen savers are loaded into an application. So mainBundle is the ScreenSaverEngine process that loaded your plugin, not your plugin. You should probably use bundleForClass to get the bundle your screensaver's main class is in.

Upvotes: 3

Related Questions