gpt4 book ai didi

javascript - 使用 URLForResource withExtension 时音频文件的 URL 无效

转载 作者:行者123 更新时间:2023-11-29 03:59:54 26 4
gpt4 key购买 nike

我的“播放”方法适用于我放入支持文件文件夹中的名为“seconds.m4a”的测试文件,但是当我 send over the file in the proper format ,该 URL 被认为无效。

我有一种强烈的感觉,这与我创建 URL 的方式有关,

NSURL* url = [[NSBundle mainBundle] URLForResource:fileURL withExtension:@"m4a"]; // THIS FORMS THE INVALID URL

插件代码:

+ (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];

}

客户端代码:

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)}

);

});

最佳答案

您引用的文件可能不在 mainBundle 中,所以我绝对不建议使用它!如果您尝试从 fileURL 获取 NSURL,那么:

[NSURL URLWithString:fileURL]

关于javascript - 使用 URLForResource withExtension 时音频文件的 URL 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16007363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com