How to create a music player for iPhone/iPad which can buffer and play songs from server? - ios

I want to develop a music player for iPhone/iPad with the functionality:
-Buffer and Play MP3 songs from server(no downloading).
-Play.
-Pause.
-Stop.
-Adjust Volume(Slider).
-Song Status/ Playing time for Song(slider).
-Repeat Song.
-Shuffle Songs.
-In the center of the Music Player there must be eq like dancing bars with song etc.
I am using AVPlayer for this but it is giving me trouble with Adjust Volume,Stop,Song Timers etc. With AVPlayer only play/pause and buffering is working.
Even i have used AVAudioPlayer also and it was working fine with all the functionality i needed but with local files only, may be i don't know any method play songs from server in AVAudioPlayer.
Help me with any suggestions,examples,sample code or tutorial.

Playing an MP3 stream seems like it should be a straightforward task that the Cocoa APIs would handle easily.
see this post Live streaming

Related

ios Can I use MPMoviePlayerController to play .mp3 url

My app needs to play some music files, like .mp3. I would like to use MPMoviePlayerController because it has implemented all the UI stuff for me, i.e. I do not want to bother implementing progress slide bar and things like this.
I tested to use it to play a .mp3 file and it worked fine but I do not know if it is fine to use it to do this because its name says "movie player" and it seems it is supposed to play a movie. Would apple reject this? Thank you.
For playing audio from a file or memory, AVAudioPlayer is your best option but unfortunately it doesn't support a network stream while MPMoviePlayerController can
From documentation :
An instance of the AVAudioPlayer class, called an audio player,
provides playback of audio data from a file or memory.
Apple recommends that you use this class for audio playback unless you
are playing audio captured from a network stream or require very low
I/O latency.
For the Apple validation I don't think that your application can be rejected because you're using the Media Player Framework to play an audio file. In fact here they explicitly say that you can do just that:
Choose the right technology for your needs:
To play the audio items in a user’s iPod library, or to play local or
streamed movies, use the Media Player framework. Classes in this
framework automatically support sending audio and video to AirPlay
devices such as Apple TV.
Not sure about performance and memory issues though!
Best of luck.

iOS - Streaming Multitrack Audio

I'm building an app in which I need to steam multiple tracks of audio that make up a song. They all need to be synchronized so the song plays back naturally.
I've been able to play back local multitrack audio very well with the solution on this thread: multi track mp3 playback for iOS application, but it looks like AVAudioPlayer isn't able to stream.
I've been looking into working with DOUAudioStreamer because I've read that it's the best solution for streaming audio on iOS without going pretty low-level, but it seems to lack the equivalent of a -playAtTime: method, which is how the tracks were synced up using `AVAudioPlayer.
Does anyone know a workaround for this using DOUAudioStreamer, or have any advice on another way I should approach this? Thanks.

How to switch among alternate audio streams using AVPlayer

I have a test application that uses AVPlayer to play video specified by an m3u8 HLS playlist. The playlist specifies several alternate audio streams, similar to the "Listing 10" sample playlist provided by Apple found here: http://developer.apple.com/library/ios/#technotes/tn2288/_index.html#//apple_ref/doc/uid/DTS40012238-CH1-ALTERNATE_MEDIA The app needs to be able to switch among the alternate audio streams while the video is playing. For example, the app should be able to switch among the English, French, and Spanish audio streams by the user tapping buttons in the app while the video is playing.
Which AVFoundation classes and methods would be used by the AVPlayer and its related objects to switch among the audio streams that are specified in the m3u8 playlist? I have looked at the AVFoundation class documentation but do not see how to do this.
A link to some sample code that shows how to do this would be great. I have been searching the web for this information without success. Thanks for any help with this.
For m3u8 playback with AVPlayer, it looks like you cannot use an AVAsset to construct an AVPlayerItem. You need to construct an AVPlayerItem from the URI directly. Upon instantiating an AVPlayer with this AVPlayerItem, and then KVO listening on the property #"status", you will have an asset within the [[avPlayerInstance currentItem] asset] if the status is AVPlayerStatusReadyToPlay. This is described on page 20 of the AV Foundation Programming Guide.
To change audio to various alternates use:
AVMediaSelectionGroup *audioSelectionGroup = [[[avPlayerInstance currentItem] asset] mediaSelectionGroupForMediaCharacteristic: AVMediaCharacteristicAudible];
NSLog(#"audioSelectionGroup: %#", audioSelectionGroup);
// [audioSelectionGroup options] // Array of the options in the group above.
And the select AVMediaSelectionOption (the audio channel you want) with:
[[avPlayerInstance currentItem] selectMediaOption:avMediaSelectionOptionInstance] inMediaSelectionGroup: audioSelectionGroup];
The same will work for video.
This is described in the "Selection of audio and subtitle media according to language and other criteria" section of the AV Foundation Release Notes for IOS 5 (3rd section).

iPhone - What's the right audio player for my app?

I'm designing a music app that plays music from the user's iPhone music library and I'm having problems figuring out which audio player is the right one to use for it (AVAudioPlayer, AVPlayer, or MPMusicPlayer).
My app needs to do the following:
Play music from the iPhone music library
Control app music volume separately from device/system volume
Continue to play app music when app moves to background
Catch events when song changes to next song or finishes
From my research it seems like each of the three audio players mentioned above do SOME of the tasks required for my app, but none of them do ALL of them. AVPlayer seems to get the closest, except its volume is dependent on the device/system volume.
Does anyone have any recommendations or workarounds to accomplish this? I've been wracking my brain over this for quite some time so any help at all would be appreciated.
EDIT
The MPMusicPlayerController class does not actually support playing background audio when getting an instance of it via + applicationMusicPlayer. The best option, then, is to simply use MPMusicPlayer to query the iPod music library. Once a song is selected by the user, the resulting MPMediaItem can be queried for it's asset URL and fed into AVPlayer's +playerWithURL, giving you full control of playback parameters.
--
I would recommend MPMusicPlayerController.
MPMusicPlayerControllerhandles the low-level details of playing audio files in the iTunes library.
You can use the class method -applicationMusicPlayer to get a local copy of the iPod singleton; from there, you can control its volume by setting its volume property for just your application.
I would assume MPMusicPlayerController has background audio support already built in. If it doesn't, you can change your app's audio session context to make it work (see Playing background audio in http://www.sagorin.org/2011/11/29/ios-playing-audio-in-background-audio/)
You can setup any object you choose to be a KVO observer of your application-specific MPMusicPlayerController object. This way, you can be notified whenever the nowPlayingItem property is changed.
Hopefully this high-level description suffices. Let me know if you need any further clarification.

Muting an AVPlayer playing Http Live Streaming video

I was wondering if I could mute the sound of an AVPlayer playing a HTTP Live Streaming video?
I've already try several things, like the Apple method to set the volume of an AVPlayer explained here but it works only for local files... (cf. the note at the bottom of Apple documentation).
The similar method explained in this post does not working either.
Is there an solution? I really don't want to mute the sound of the device but only one video while other players could have their own audio (the user could balance audio between players).
Thanks in advance.
iOS 7.0 now provides support for muting the player using
[AVPlayer setVolume:(float)volume]
It also works for HTTP Live Streaming, my app is making extensive use of it.
According to the AVFoundation team, it is impossible to mute or disable a track of an HLS video.
You can mute the entire audio session using MPMusicPlayerController shared instance.
[[MPMusicPlayerController applicationMusicPlayer ]setVolume:0];

Resources