Hi everyone,
I think, all of you heard about live audio/video streaming. I'm going to share "Live Audio Streaming" example with you.
Please check this :
Step 1: First of all, you have to download these two files(AudioStreamer.h, AudioStreamer.m) from http://code.google.com/p/audiostreamer-meta/source/browse/trunk/Classes
Step 2: Add necessary frameworks and above two files into your project.
Step 3: Implement below code to your project file.
@class AudioStreamer;
@interface CallerTuneListViewController : UIViewController
{
AudioStreamer *streamer;
}
#import "CallerTuneListViewController.h"
#import "AudioStreamer.h"
#import <QuartzCore/CoreAnimation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <CFNetwork/CFNetwork.h>
#import <AudioToolbox/AudioToolbox.h>
@implementation CallerTuneListViewController
#pragma mark ---------------------------------
#pragma mark View LifeCycle
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if ([streamer isPlaying]) {
[self destroyStreamer];
}
}
#pragma mark ---------------------------------
#pragma mark Memory Management
- (void)dealloc
{
[self destroyStreamer];
[super dealloc];
}
#pragma mark ---------------------------------
#pragma mark UIButton Actions
-(IBAction)playLiveStream:(id)sender
{
if (![streamer isPlaying])
{
[self createStreamer:AudioFilePath];
[streamer start];
}
else
{
[streamer stop];
}
}
#pragma mark ---------------------------------
#pragma mark AudioStreamer Methods
// Removes the streamer, the UI update timer and the change notification
- (void)destroyStreamer
{
if (streamer)
{
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:ASStatusChangedNotification
object:streamer];
[streamer stop];
[streamer release];
streamer = nil;
}
}
// Creates or recreates the AudioStreamer object.
- (void)createStreamer:(NSString *)audioPath
{
if (streamer)
{
return;
}
[self destroyStreamer];
NSURL *url = [NSURL URLWithString:audioPath];
streamer = [[AudioStreamer alloc] initWithURL:url];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(playbackStateChanged:)
name:ASStatusChangedNotification
object:streamer];
}
// Invoked when the AudioStreamer
// reports that its playback status has changed.
- (void)playbackStateChanged:(NSNotification *)aNotification
{
if ([streamer isWaiting])
{
}
else if ([streamer isPlaying])
{
}
else if ([streamer isIdle])
{
[self destroyStreamer];
}
}
I hope this will be useful to all...
Thanks ,
Nilesh M. Prajapati
I think, all of you heard about live audio/video streaming. I'm going to share "Live Audio Streaming" example with you.
Please check this :
Step 1: First of all, you have to download these two files(AudioStreamer.h, AudioStreamer.m) from http://code.google.com/p/audiostreamer-meta/source/browse/trunk/Classes
Step 2: Add necessary frameworks and above two files into your project.
Step 3: Implement below code to your project file.
@class AudioStreamer;
@interface CallerTuneListViewController : UIViewController
{
AudioStreamer *streamer;
}
#import "CallerTuneListViewController.h"
#import "AudioStreamer.h"
#import <QuartzCore/CoreAnimation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <CFNetwork/CFNetwork.h>
#import <AudioToolbox/AudioToolbox.h>
@implementation CallerTuneListViewController
#pragma mark ---------------------------------
#pragma mark View LifeCycle
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if ([streamer isPlaying]) {
[self destroyStreamer];
}
}
#pragma mark ---------------------------------
#pragma mark Memory Management
- (void)dealloc
{
[self destroyStreamer];
[super dealloc];
}
#pragma mark ---------------------------------
#pragma mark UIButton Actions
-(IBAction)playLiveStream:(id)sender
{
if (![streamer isPlaying])
{
[self createStreamer:AudioFilePath];
[streamer start];
}
else
{
[streamer stop];
}
}
#pragma mark ---------------------------------
#pragma mark AudioStreamer Methods
// Removes the streamer, the UI update timer and the change notification
- (void)destroyStreamer
{
if (streamer)
{
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:ASStatusChangedNotification
object:streamer];
[streamer stop];
[streamer release];
streamer = nil;
}
}
// Creates or recreates the AudioStreamer object.
- (void)createStreamer:(NSString *)audioPath
{
if (streamer)
{
return;
}
[self destroyStreamer];
NSURL *url = [NSURL URLWithString:audioPath];
streamer = [[AudioStreamer alloc] initWithURL:url];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(playbackStateChanged:)
name:ASStatusChangedNotification
object:streamer];
}
// Invoked when the AudioStreamer
// reports that its playback status has changed.
- (void)playbackStateChanged:(NSNotification *)aNotification
{
if ([streamer isWaiting])
{
}
else if ([streamer isPlaying])
{
}
else if ([streamer isIdle])
{
[self destroyStreamer];
}
}
I hope this will be useful to all...
Thanks ,
Nilesh M. Prajapati
hey Nilesh,
ReplyDeleteGood post , am adding MATT's Audiostreamer in my project .
The thing is that i have an array of remote mp3 urls ,i want to pass it in this streamer , how to achieve it ? help needed!!!
Thanks for your complement..
ReplyDeleteAs I write code for "createStreamer", using that function you can create your audio streamer as just adding mp3 url one by one.
can you provibe the sample code please
ReplyDeleteHi,
ReplyDeleteYou can go with Google code link .. and follow the steps which I had mentioned in this post.
Good luck.
Thanks,
Nilesh Prajapati
hi,
ReplyDeletecan we save stream coming from server
Hi,
DeleteYes it is possible to store stream coming from server. But it also depends on the contents' privacy too.
Hi Nilesh How do i Broadcast Audio which stored in Music like Radio and other user can listen real time can you please share your idea or link
ReplyDelete