IPhone SDK (Beta 5) - AudioQueue Problem playing MP3

Dear community,
i have a problem using the iPhone SDK (Beta 5). I want to playback a simple MP3-file. So i checked a lot of examples, read documentation and found a least the "AudioQueueTest" example. This is an simple example which is able to play MP3, WAV, ... from the command line. I ported the example to a simple application on the iPhone. Now the problem:
If i playback a WAV file in the iPhone simulator, everything works fine. If i want to playback an MP3 file, it doesn't work and i don't know why. I stepped through the debugger and found out that the application freezes at the command "AudioQueueNewOutput".
Do you have the same problem? What i am doing wrong? Is it no possible to create a background thread playing back a local MP3 file?
Thank you!

Did you get PCM recording on actual iPhone hardware? With Beta5, my PCM recording works fine in the simulator, but on the hardware, all the buffers I receive contain only 4 bytes of audio data!
Here's my source code - if anyone can spot anything wrong, I'd be enormously grateful!
#import "AudioAppDelegate.h"
#import "AudioViewController.h"
#import "AudioToolbox/AudioQueue.h"
#define BUFFER_CT 4
#define BUFFER_BYTES 8192
AudioQueueRef audioInQueue;
static void AudioInCallback(void* aqData,AudioQueueRef aq,AudioQueueBufferRef buffer,const AudioTimeStamp* startTime,UInt32 numPackets,const AudioStreamPacketDescription* desc)
OSStatus result;
printf("received %d bytes\n",buffer->mAudioDataByteSize);
result=AudioQueueEnqueueBuffer(audioInQueue,buffer,0,NULL);
if(result)
printf("AudioQueueEnqueueBuffer returned %d\n",result);
static void StartAudio(void)
OSStatus result;
AudioStreamBasicDescription format;
// 11KHz, 16-bit stereo
memset(&format,0,sizeof(format));
format.mSampleRate=11025;
format.mFormatFlags=kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
format.mFormatID=kAudioFormatLinearPCM;
format.mBytesPerPacket=BUFFER_BYTES;
format.mBytesPerFrame=4;
format.mFramesPerPacket=format.mBytesPerPacket / format.mBytesPerFrame;
format.mChannelsPerFrame=2;
format.mBitsPerChannel=16;
result=AudioQueueNewInput(&format,AudioInCallback,NULL,CFRunLoopGetCurrent(),kC FRunLoopCommonModes,0,&audioInQueue);
printf("AudioQueueNewInput result was %d\n",result);
for(int i=0;i<BUFFER_CT;i++)
AudioQueueBufferRef buffer;
result=AudioQueueAllocateBuffer(audioInQueue,format.mBytesPerPacket,&buffer);
printf("AudioQueueAllocateBuffer result was %d\n",result);
result=AudioQueueEnqueueBuffer(audioInQueue,buffer,0,NULL);
printf("AudioQueueEnqueueBuffer to in result was %d\n",result);
Float32 gain=1.0;
AudioQueueSetParameter(audioInQueue,kAudioQueueParam_Volume,gain);
result=AudioQueueStart(audioInQueue,NULL);
printf("AudioQueueStart result was %d\n",result);
}

Similar Messages

  • Problems playing mp3s after installing iTunes 7.1

    I installed iTunes 7.1 today. After that, I have problems playing mp3 songs on my iPod (80 GB). The AAC-files play well. The mp3 songs can also be played on iPod via iTunes when its connected to my computer, but when I disconnect from the computer, the mp3 songs starts, and play for about 2 second, and then jumps to the end of the song and stop.
    Very thankful for any help.

    that's typically caused by a problem with your QuickTime. (itunes uses QuickTime for audio and video playback.)
    the following document may be of some assistance:
    iTunes 7 for Windows: iTunes had detected an audio configuration problem

  • IPhone SDK Beta 4 - How to send emails with attachments?

    Hello everyone!
    This is my first post Please be so kind to point me in the right direction.
    Using the official iPhone SDK Beta 4, I am trying to show the compose email screen not only with a subject and body fields, but also with an attached PDF file that I generated. I know that many apps available in the Installer.app can do that, but can the SDK do that as well?
    Generating a mailto URL doesn't seem to be the answer since the RFC 2368 doesn't support attachments as far as I understand. All my attempts to hard-code a mailto URL that could trick the Mail application into composing a message with an attachment have failed...
    Could you give me a hint or maybe copy paste some code to help me with attaching files to emails?
    Thank you so much in advance,
    Eugene

    I tried the following :
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"export.csv"];
    if ([records writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error] == NO) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Export error" message:@"An error occured while writing the file."
    delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];
    static NSString *email = @"[email protected]";
    NSString *outMailtoPath = [NSString stringWithFormat:@"mailto:%@?subject=Review&body=%@&attachment=%@", email, @"test", path, nil];
    NSURL *url = [NSURL URLWithString: [(NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)outMailtoPath,NULL,NULL,kCFStringEncodingUTF8) autorelease]];
    [[UIApplication sharedApplication] openURL:url]

  • Still having problems playing MP3s on Mac OS 10.5

    Hi everyone,
    I was never able to solve this issue, and moved on to other things, but I'm stumbling over it again. I believe that I have everything set up properly; I put the jmf and mp3 plugin jars in my /Library/Java/Extensions folder, but I am getting this message when I try running java com.sun.media.codec.audio.mp3.JavaDecoder:
    java.lang.reflect.InvocationTargetException
    Registered succesfully
    So does that mean it's properly registered, or is that InvocationTargetException something tats causing a problem. The JMF works fine for everything but mp3s; when I try playing an MP3 file, I get this error:
    Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 16000.0 frame rate, FrameSize=32768 bits
    Failed to realize: com.sun.media.PlaybackEngine@39b3a2
    Error: Unable to realize com.sun.media.PlaybackEngine@39b3a2
    All of the files I've tested worked fine with the JMStudio application that came with the JMF, but when I compiled JMStudio on my system, I got the same results that I describe above.
    I've installed, uninstalled, and reinstalled the JMF and the mp3 plugin a couple times now, and then have run the jmfinit binary, and then the jmfregistry binary, and then added and committed the com.sun.media.codec.audio.mp3.JavaDecoder to the Plugins->Codec menu. Again, with the results that I have described above.
    Can anyone help?

    I have had some success adding the [JMF codec|http://java.sun.com/javase/technologies/desktop/media/jmf/mp3/download.html] to the run-time classpath of the application (or applet).
    I did not 'install' any version of the JMF to this Ubuntu system, but separately downloaded the (MP3 codec) Jar and just added it to the classpath (at run-time).
    Note there are a number of MP3s that the JMF codec fails to get an input stream from. I recommend anybody attempting this, try it first with an MP3 that has been seen to work using the JMF codec. As such you might..
    a) Visit this applet(1), which tries to load/play an MP3. And if that works OK on your Mac., then go to..
    b) Visit the [sound section of my media page|http://pscode.org/media/#sound] and download the 'Dead End' MP3 for your own local testing.
    (1) The applet Jars are digitally signed. You can safely refuse the digitally signed code and the applet should still work. The applet is still experimental - if you have any problems with it, I would appreciate hearing them. Part a) is effectively an 'acid test' on whether my attempts to play MP3s in applets for Mac users (and other visitors) is successful. If it fails, it might indicate a difference in the way Macs implement the SPI.

  • IPhone SDK Beta 2 Interface Builder Add a UIViewController

    Hi,
    I am trying the new SDK (beta 2). I didn't try the beta 1 before, because of the lack of IB. However, I am having a problem when trying to code a simple Hello World with a button, with a classic MVC design.
    If I use a UIViewController as a view controller, it compiles fine, but when I hit the button, it crashed. If I code it, or if I subclass the UIView and use it as a view controller, it works.
    Is there any difference of coding compared to a "classic" cocoa app ?
    I hope everything is clear.
    Thanks for your help.
    Have a great day.

    scottjg wrote:
    I've written a tutorial on how to setup a basic Hello World MVC app at: http://ihatetheiphonesdk.blogspot.com
    hope it helps!
    thanks. That helped me!
    A couple of issues though:
    1. I could not "*right click*" and bring up the outlet popups. I had to control-click to do that.
    2. the steps for connecting up outlets for viewController and window did not exist already for me as selectable outlets
    "-Connect our App Delegate's viewController outlet to our view controller, and the window outlet to our window:"
    I added them manually to the app delegate and then ran the connections. Then, I had to add
    +" IBOutlet UIWindow *window;+
    +IBOutlet UIViewController *viewController;"+
    to my HelloWorldAppDelegate.h file (along with any other code that I compared to your files)

  • Interface Builder not starting (iPhone SDK beta 6)

    Hi,
    I have upgraded my OS to 10.5.3, uninstalled SDK beta 5 and installed SDK beta 6. Since then I cannot start Interface Builder (the icon bounces 3 or 4 times and the application hangs). I tried to reinstall it again and nothing changed.
    Is that a known problem with beta 6? I have a friend who does not experience this problem. Any workaround?
    Thanks and best,
    Rodrigo

    How can it be possible? you invest some money believeng you will start something great and develop allied with the biggest intrepeneur of the world,and... boom. what you see.... isnt really what u get. Why this beta 6/7 Interface Builder crashs when u scroll around too see some v2.0 aspects of the i-phone? just some secret aspects or a little glitch on the final build ? lets see if we can have a taste for it... i was really anxious...

  • Safari 4.0.5. problems playing mp3 files.

    Hi,
    I'm having trouble playing mp3 files on my iWeb created website. When I use Safari (4.0.5) to browse, Safari does not display the player part of the mp3., and on my welcome page, it does not play the music that's set to autoplay.
    When I use Firefox to browse the same website, all mp3 files work fine, including the mp3 set to autoplay on the welcome page !
    I also tested browsing with Safari 4.0.4 running on OSX 10.5.8, (on another computer), and it works fine !
    I'm guessing this means something is buggy with Safari 4.0.5. running on OSX 10.6.3. or could it be something else ?
    Anyone notice this type of issues with Safari 4.0.5. ?
    Some feedback would be appreciated.
    Thanks.

    Thanks for confirming that you are experiencing a similar issue when using Safari 4.0.5 and try to play your mp3 files. As I mentioned earlier, Firefox displays, and plays the files perfectly !
    This must be some kind of bug in 4.0.5. that Apple needs to fix.
    I already sent Apple a bug report.
    By the way, I used another computer running OSX 10.5.8 and Safari 4.0.4 to test my site, and found no issue, Safari 4.0.4 works fine, it played the autoplay mp3 file, and displayed the mp3 player without any issues. Which seems to indicate that this is a Safari 4.0.5. issue.

  • Problems playing mp3 in Chrome and Firefox

    Hi
    I have added a small MP3 file to a page in DW which plays perfectly in I.E., Safari and Opera. But in Google Chrome the audio player appears at the top of the screen and I see a black rectangle exactly where it should appear on the page (which is not at the top of the page).
    In Firefox I get a the Install Missing Plugin message after which it tells me 'no suitable plugins were found'. As I said, everthing works fine in all other browsers.
    I am using DW CS5,5 for Windows, Windows 7, Chrome and Firefox 10. I have heard somewhere that Firefox does not support MP3 due to licensing issues but I don't how true this is. Any help and advice will be much appredciated.
    Thanks
    George.

    I'm also experiencing this problem.
    My page is:
    http://curumba.net/TEXTOS/AUDIOS/MENSAGEM-39.html
    The sound starts play without the command and the image appearsat the top of the page
    thank you

  • [iPhone SDK beta 7] screen capture error?

    As of beta 7 of the SDK, I get the following error when I try to capture a screenshot of my device via Xcode: "Could not communicate with the device, connection failed".
    Anyone else encounter this? Or is it working for you?
    Thanks.
    Message was edited by: Abra Dabra

    Me, too. Xcode 3.1. I am using the old-fashioned screen capture technique (holding power while pressing home), but it's not nearly as nice and the fact I can't do the other worries me a bit.
    Has anyone been able to do this since iPhone 2.1 came out?

  • IPhone SDK beta 4: error running app on device

    My app ran fine on my iPhone up until beta 4. I've fixed in in accordance with the changes to the SDK, and it runs perfectly on the simulator. I've also followed the directions in the Program Portal to use code signing for the app.
    When I try to compile it for the device, I get the following errors:
    cc1obj: error: /var/folders/pA/pAvrzjzKGQe5O6saRJWAXE+TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/iCrosswordPrefix-ayguzoobuyunjzbvsayctaqnkcfp/iCrosswordPrefix.pch: No such file or directory
    cc1obj: error: one or more PCH files were found, but they were invalid
    cc1obj: error: use -Winvalid-pch for more information
    I get about 7 copies of those errors, once per header file in my app.
    Does anyone know what this means, or how to fix it?
    Thanks,
    Eliza

    Sorry, I'm an idiot; I didn't clean my targets before compiling. After cleaning targets, it installed and ran without any trouble.
    Message was edited by: Eliza Block

  • [iPhone SDK] disabling fading effect when playing movie

    Thanks to the MPMoviePlayerController class and the exemples in the documentation, it is quite easy to play a video on the iPhone.
    However, I would like to disable the fading effect occuring at the beginning and the end of a video playback: does anybody knows how to do?

    More details about what I'm trying to do, in case it might help:
    The last frame of the video is exactly the same than the background picture which is displayed right after the video finish playing, and correspond to the application main interface.
    To give the user a nice feeling, it is important to keep the transition between the video and the application main background as smooth (and invisible) as possible, which is why I would love to remove those fading effects...
    One solution to remove the final fade effect could be to stop the video before its 'real' end (by duplicating final frame at least more than fade effect time - don't know if it work, I didn't tried), but there will still be the problem of the initial fade, which is maybe worse than final one
    Any suggestion welcome!
    Thanks.

  • IPhone SDK Beta and Unix Tools

    Does anyone know how to compile Unix tools for the iPhone with the SDK? All I seem to be able to find is, "install the toolchain". That doesn't help.
    Specifically, I'd like to compile ettercap-ng. I know ettercap has ARM sources and even an ARM .deb in the apt-get repo (for debian). Given all that, it shouldn't be hard to do.
    I've already got some dev tools on my actual iPhone, and I can use a terminal emulator to issue the compile and make commands.
    I'm trying to compile ettercap-NG 0.7.3, and every time I do, (cd /{ettercap source here} && ./configure) I get:
    checking whether make sets $(MAKE)... (cached) yes
    checking how to run the C preprocessor... /lib/cpp
    configure: error: C preprocessor "/lib/cpp" fails sanity check
    See `config.log' for more details.
    Seeing as that's as far as I seem to be able to get on the actual handset, does anyone know how to use the SDK on a MacBook (Leopard 10.5.3 so on and so forth) to do it, and then transfer it over?

    Mark, You have to be a registered iPhone developer to have the beta level firmware that allows direct access to the iPhone via the SDK. As far as accessing the BSD file structures the only way AFAIK thats currently possible is to hack the phone. And of course we cannot discuss that on this forum....
    Try over here: http://www.appstoredeveloper.com/forum/index.php?sid=fdd5a5f29c264bd57440ba989ee 4b054
    or here: http://www.modmyifone.com/forums/iphone-ipod-touch-sdk-development-discussion/

  • Problems playing Mp3's

    I have a big list of music that used to play in iTunes, but now they don't play anymore. I tried to remove them from the list and reload them and now it wont even put them on the list, also no errors come up. Also tried reinstalling iTunes with no luck. These songs do play when loaded into another player. Has anyone experienced this and know how to fix it?

    It's possible that the headers on the problem tracks may have become corrupted (this can happen if you used any sort of tag editor on the tracks or played or altered them with other software). If you search the web for "mp3 repair" you'll find a number of repair tools. Here are a couple I've seen mentioned:
    MP3 Validator
    VBRfix.
    I haven't tried any of the versions of either, so I can't attest to how well (or indeed if) they work. They might be worth a try on a few test tracks, though, to see if it gets them playing.
    Hope this helps.

  • [iphone sdk] audio queue programming problem

    hello everyone, this is my first post. i am new to mac/iphone programming and need some help.
    i am trying to play a simple .wav file in my iphone app and can't get it to work. here is my code.
    //here is the structure i use to keep track of the data
    typedef struct AQPlayerState {
    AudioStreamBasicDescription mDataFormat;
    AudioQueueRef mQueue;
    AudioQueueBufferRef mBuffers[3];
    AudioFileID mAudioFile;
    UInt32 bufferByteSize;
    SInt64 mCurrentPacket;
    UInt32 mNumPacketsToRead;
    bool mIsRunning;
    } AQPlayerState;
    //here is the callback function
    static void HandleOutputBuffer(void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer)
    //typecast the AQPlayerState struct
    AQPlayerState *pAqData = (AQPlayerState *)aqData;
    //if it's already done playing, return
    if(pAqData->mIsRunning == true)
    return;
    //set up the read data
    UInt32 numBytesReadFromFile;
    UInt32 numPackets = pAqData->mNumPacketsToRead;
    //read in from the audio file
    OSStatus status1 = AudioFileReadPackets(pAqData->mAudioFile, false, &numBytesReadFromFile, NULL, pAqData->mCurrentPacket, &numPackets, inBuffer->mAudioData);
    //set the number of packets in the buffer
    inBuffer->mAudioDataByteSize = numBytesReadFromFile;
    //increment the packet index
    pAqData->mCurrentPacket += numPackets;
    //enqueue the data
    OSStatus status2 = AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL);
    //stop the playback if needed
    if(numPackets == 0)
    AudioQueueStop(inAQ, false);
    pAqData->mIsRunning = false;
    //here is where i create the audio queue and buffers
    //open the audio file
    NSString *nspath1 = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"wav"];
    CFStringRef path1 = CFStringCreateWithCString(NULL, [nspath1 UTF8String], kCFStringEncodingUTF8);
    CFURLRef url1 = CFURLCreateWithFileSystemPath(NULL, path1, kCFURLPOSIXPathStyle, NULL);
    //open the file and get the data format
    OSStatus status1 = AudioFileOpenURL(url1, fsRdPerm, 0, &aqData.mAudioFile);
    UInt32 dataFormatSize = sizeof(aqData.mDataFormat);
    AudioFileGetProperty(aqData.mAudioFile, kAudioFilePropertyDataFormat, &dataFormatSize, &aqData.mDataFormat);
    //create the output queue
    OSStatus status2 = AudioQueueNewOutput(&aqData.mDataFormat, HandleOutputBuffer, &aqData, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &aqData.mQueue);
    //get the max packet size
    UInt32 maxPacketSize;
    UInt32 propertySize = sizeof (maxPacketSize);
    AudioFileGetProperty(aqData.mAudioFile, kAudioFilePropertyPacketSizeUpperBound, &propertySize, &maxPacketSize);
    //set the buffer size and how many packets to read each time
    aqData.bufferByteSize = 44100 * 4;
    aqData.mNumPacketsToRead = aqData.bufferByteSize / maxPacketSize;
    //set the current packet to be read, create the buffers and prime them
    aqData.mCurrentPacket = 0;
    for(int i = 0; i < 3; i++)
    OSStatus status3 = AudioQueueAllocateBuffer(aqData.mQueue, aqData.bufferByteSize, &aqData.mBuffers);
    HandleOutputBuffer(&aqData, aqData.mQueue, aqData.mBuffers);
    //set the gain and start playback
    AudioQueueSetParameter(aqData.mQueue, kAudioQueueParam_Volume, 1.0);
    AudioQueueStart(aqData.mQueue, NULL);
    //here is the code right below of where i create the queue and buffers
    NSString *nspath = [[NSBundle mainBundle] pathForResource:@"white" ofType:@"png"];
    CFStringRef path = CFStringCreateWithCString(NULL, [nspath UTF8String], kCFStringEncodingUTF8);
    CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, NULL);
    CGDataProviderRef provider = CGDataProviderCreateWithURL(url);
    whitePNG = CGImageCreateWithPNGDataProvider(provider, NULL, true, kCGRenderingIntentDefault);
    now, when it runs and, all of the audio function return a value of 0, which means successful, right? what happens is that it gets to the last line i listed (starting with whitePNG = ) and i get a BAD_ACCESS message in the debugger. that code worked just fine before i added the audio stuff, so i don't understand why it's broke now.
    if i comment out the enqueue function in the callback, it will run just fine, but the return value of that is not an error, so i don't understand. i am completely new to audio programming, so i need some help. is the buffer size and packet read size wrong? i'm confused. i am trying to play a .wav file that is 16 bit, 44100 PCM.
    please help, i don't see anything wrong with the code.
    Message was edited by: jharkey

    //if it's already done playing, return
    if(pAqData->mIsRunning == true)
    return;
    this is actually
    //if it's already done playing, return
    if(pAqData->mIsRunning == false)
    return;
    i had that typed wrong in the code, but after i changed it i still get the errors.

  • IPhone SDK 2.2: Localization problem?

    Can anybody replicate that Localizeable.strings no longer work?
    Set up:
    - SDK 2.2 final installed.
    - Localizeable.strings in de.lproj and en.lproj.
    - Compiled Debug for OS 2.1.
    - Works perfectly fine for both languages on Simulator.
    - Does not work on 3G device.
    Can anybody duplicate problems with Localizeable.strings? Any hints?

    Can anyone confirm that this is the problem, and that this solves the problem? I haven't had a chance to try it myself. I saw on another forum, which was in Russian so I'm not sure I understood it all correctly, that there was an issue where the SDK wants the files to now be called Localizable.strings.<some number>. So I'm wondering if that is just an incorrect item, or if there may perhaps be multiple solutions?

Maybe you are looking for