2

I currently have 3 ways to play audio within my app:

  1. Using AudioServicesPlaySystemSound for vibration and simple sounds

  2. Using Audio Toolbox for bundled files (3rd party class)

  3. Using AudioServices with AudioFX

What I'm currently investigating is, if I can play other kinds of audio that are already present on the iPhone. I would like to reduce my app's download size, as well as offer more flexibility in terms of the kind of sound that the user can play.

Can I play from within my app:

  1. Audio recordings from the Voice Memos app, or do I have to
  2. create my own recordings? Items from an iPod playlist or Music app?
  3. Items from youtube by pre-loading them, or will I have to stream them every time?
  4. Existing ringtone for the phone?

I am a complete beginner when it comes down to playing audio on an iPhone and am already using two 3rd party classes for audio tasks.

Is there an easy way to accomplish some of the tasks listed above?

User97693321
  • 3,336
  • 7
  • 45
  • 69
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
  • 1
    You can play sound from 1. iPod Library 2. Online Source (for which you need to stream every time. Not sure about Existing Ringtones. No need to use any 3rd Party classes for audio task. You have 3 Framework classes for playing audio. 1. AudioUnit 2. AVAudioPlayer 3. MPMediaPlayer. All are having their own advantages and disadvantages. Please refer to apple's documentation for more details. – DShah Nov 07 '11 at 05:32

2 Answers2

3

1) Audio recordings from the Voice Memos app

It's been asked before and I don't believe it's possible from your app sandbox.

iPhone: Access voice memos programmatically

2) Items from an iPod playlist or Music app

There's an API for that, the iPod Access Library:

http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/iPodLibraryAccess_Guide/Introduction/Introduction.html

3) Items from youtube

Should be possible, using a UIWebView.

http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application

4) Existing ringtone for the phone

No, you can't access the current ringtone programatically.

How can I programmatically determine the default ringtone on an iPhone?

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
1

You can download sound files on first start (not in your didFinishLaunchingWithOptions method or your app will likely be killed) and save them locally, then you can just play them when needed. You can play files in their iTunes library, but won't know what they have in the library.

To play from their library, this is a handy example:

http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-music-library-access/

You can also record user input from your app with AVAudioRecorder, save that and then play it whenever.

Norman
  • 453
  • 3
  • 5
  • This project looks very interesting, and I like that I can import and test it easily! – Alex Stone Nov 07 '11 at 17:36
  • Just compiled this tutorial, it is exactly what I've been looking for! With access to the music library, other methods pale in comparison! A ringtone can be added to an itunes music library and synced with the device if I need to play one. Thank you very much – Alex Stone Nov 07 '11 at 17:45