View Full Version : Unable to play a .mp3 file directly using QTMovie

Oct 5, 2010, 06:27 AM
Hi all,

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 not working for me ie. no audio gets played :(

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




The sample code can be downloaded from here- Sample Code Download Link (http://db.tt/cDjFCZO)

One of the example links which I tried was - In the end song (http://javamax.free.fr/sonorisation%20et%20radio/Linken%20Park%20-%20In%20The%20End.mp3)

Oct 5, 2010, 07:15 AM
Instead of passing nil to the error param pass an error pointer as expected and look at the error to find out what's wrong.

Oct 5, 2010, 03:29 PM
If you're pasting in that URL and then encoding it again, it'll mess it up. Try creating the URL from the text field directly.

Oct 5, 2010, 06:19 PM
NSURL *audioUrl = [[NSURL alloc] initWithString:[audioInputTextField stringValue]];
if (![QTMovie canInitWithURL: audioUrl]) {
NSLog(@"Cannot init with url");

Though you have to press the "go" (blank button) twice...
I saw that you have a .mp3 in the folder, note that file URL's need to be initialized with - initFileURLWithPath: (NSString *)

(this hung me up for a while while troubleshooting...) :p

EDIT: Oh and that little if statement there was helpful while testing, though I did initially send and print off and NSError * to it.