开发者

Unable to play a .mp3 file directly using QTMovie

开发者 https://www.devze.com 2023-01-19 05:27 出处:网络
I am trying to play a .mp3 file on click of a button using this code: NSString *audioFilePath=[[audioInputTextField stringValue] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

I am trying to play a .mp3 file on click of a button using this code:

NSString *audioFilePath=[[audioInputTextField stringValue] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *audioUrl = [[NSURL alloc] initWithString:audioFilePath];
QTMovie* soundToPlay = [[QTMovie alloc] initWithURL:audioUrl error:nil];
[soundToPlay play];

Here user is expected to enter a valid url for an audio file in text field and then click button next to it to play, but it is开发者_如何学Python not working for me ie. no audio gets played :(

Can anyone suggest me, if I am doing anything wrong?

Thanks,

Miraaj


The sample code can be downloaded from here- Sample Code download link

One of the example links which I tried was - In the end song


Is audioFilePath a valid file system path? Is audioUrl a valid file URL or is it nil? To me it looks unlikely since you're giving a url-encoded path and trying to initialize a new URL with that string.

Your audioFilePath should be a valid /Path/To/Folder/File.mp3 and if you have a basic file path, you should create your URL with NSURL's +fileURLWithPath: convenience method.


You entered a URL with characters already percent-escaped, and then your program added percent escapes. This means that you double-escaped the characters, turning the correct “%20”s into incorrect “%2520”s.

Try it both ways: Try the URL without escaping first, then if it fails, add percent escapes and try again. If that fails, present the error that initWithURL:error: gave you.

0

精彩评论

暂无评论...
验证码 换一张
取 消