Unable to play a .mp3 file directly using QTMovie

Discussion in 'Mac Programming' started by Monaj, Oct 5, 2010.

  1. macrumors regular

    Joined:
    May 24, 2009
    #1
    Hi all,

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

    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?

    Thanks,

    Monaj

    -------

    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
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    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.
     
  4. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #4
    Code:
    	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.
     

Share This Page