My 'play' method works with a test file I put in the Supporting Files folder called "seconds.m4a", but when I send over the file in the proper format, the URL is said to be invalid.
I have a strong feeling it has something to do with the way I'm creating the URL,
NSURL* url = [[NSBundle mainBundle] URLForResource:fileURL withExtension:@"m4a"]; // THIS FORMS THE INVALID URL
PLUGIN CODE:
+ (void)play:(ForgeTask*)task {
// parse the file url from the file object
ForgeFile* file = [[ForgeFile alloc] initWithFile:[task.params objectForKey:@"file"]];
NSString* fileURL = [file url]; // eg. "/var/mobile/Applications/AC963D11-88EC-4559-9C2E-68F666AC44D5/Library/Application Support/Forge/assets-6B531B6A-AF26-44FB-BCB1-D036BD4A7293/src/audio/seconds.m4a"
NSLog(@"Playing file at %@", fileURL);
NSURL* url = [[NSBundle mainBundle] URLForResource:fileURL withExtension:@"m4a"]; // THIS FORMS THE INVALID URL
// TESTING - THIS WORKS IN THE FORGEINSPECTOR WHEN UNCOMMENTED
//url = [[NSBundle mainBundle] URLForResource:@"seconds" withExtension:@"m4a"];
// END TESTING
NSAssert(url, @"URL is invalid."); // THIS IS THE ERROR MESSAGE THAT COMES UP
// create the player
NSError* error = nil;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if(!player)
{
NSLog(@"Error creating player: %@", error);
};
[player play];
[task success:nil];
}
CLIENT CODE:
forge.file.getLocal('/audio/seconds.m4a', function(file) {
debug(null, file); // SHOWS THE PROPER FILE: {"uri":"/var/mobile/Applications/AC963D11-88EC-4559-9C2E-68F666AC44D5/Library/Application Support/Forge/assets-6B531B6A-AF26-44FB-BCB1-D036BD4A7293/src/audio/seconds.m4a"}
forge.internal.call(
'audio.play',
{file: file},
function () { alert('Success!') },
function (e) { alert('Error: '+e.message)}
);
});