I want to stop streaming mp3 file in UIWebview without reload page.
So I don't want reload page to stop. It's not best way. Does anyone suggest an idea for me ?
Thanks in advance !
You simply load blank page to stop streaming mp3 file.
Like this :
[self.yrwebContent loadRequest:NSURLRequestFromString(#"about:blank")];
UPDATE: Another solution, play sound using AVAudioPlayer instead
NSURL *url = [NSURL fileURLWithPath:self.sFilePath];
NSData *yrSound = [NSData dataWithContentsOfURL:url];
AVAudioPlayer *SoundPlayer = [[AVAudioPlayer alloc] initWithData:yrSound error:NULL];
SoundPlayer.numberOfLoops = 0;
[SoundPlayer play];
Then, you stop it by using :
[SoundPlayer stop];
Related
I am new to iOS and I was searching fix for this issue since morning and didn't find the solution yet, I have more than 6000 sound files online which i want to play using AVAudioPlayer when user click on the cell, so i implemented it in didSelectRowAtIndexPath:
like this :
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#", [soundsArray objectAtIndex:(int)indexPath.row]];
NSData *soundData = [NSData dataWithContentsOfURL:url];
_audioPlayer = [[AVAudioPlayer alloc] initWithData:soundData error:NULL];
[_audioPlayer play];
}
the problem is, whenever i click on any row, the whole UI freezes till the time it takes to load the complete sound file from internet,
for larger files , it takes longer.
I tried with AVPlayer and it is working fine, but I need AVAudioPlayer becouse it seems easy to me to work with
-(void)AVAudioPlayerDidFinishPlaying:(AVAudioPlayer *)Player successfully:(BOOL)flag
thats why I want to implement it with AVAudioPlayer
I hope you understood my problem,
Sorry for my bad English.
Never use
NSData *soundData = [NSData dataWithContentsOfURL:url];
this will block your UI.
You need to use NSURLSession to download data asynchronously.
Sorry for bad Engilsh.
I am new to iOS development.And I am trying to create a client application which stream .m4a audio file from stream url
rtsp://192.168.1.50:1935/TestServer/abc.m4a
and play it on button click.
I have tried almost every thing which I can find but I was not able to get and play stream.
There is my code which play audio from http url
- (IBAction)btn:(id)sender {
NSString *str = #"http://download.wavetlan.com/SVV/Media/HTTP/AAC/Nero_Soundtrax/NeroSoundTrax_test1_AAC-LC_v4_Stereo_CBR_96kbps_44100Hz.m4a";
NSString *urlStr = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL * mediaURL = [NSURL URLWithString:urlStr];
player = [AVPlayer playerWithURL:mediaURL];
[player play];
}
but I want to play audio file from this type of url. rtsp://192.168.1.50:1935/TestServer/abc.m4a
i tested my streaming url on VLC to verify. It works perfect but when I put that url on button click code it didn't work.
I try to use ffmpeg library but did not find luck in that.
Try register audio session category before playing.
- (IBAction)btn:(id)sender {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];
NSString *str = #"http://download.wavetlan.com/SVV/Media/HTTP/AAC/Nero_Soundtrax/NeroSoundTrax_test1_AAC-LC_v4_Stereo_CBR_96kbps_44100Hz.m4a";
NSString *urlStr = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL * mediaURL = [NSURL URLWithString:urlStr];
player = [AVPlayer playerWithURL:mediaURL];
[player play];
}
Hope this helps.
Standard iOS frameworks do not support RTSP playback, so you will have to use some third-party solution.
Hope this post helps:
https://gist.github.com/oc2pcoj/e55795550984d205d109
i am trying to make an online audio player. but i can't paly audio using AVAudioPlayer object. Please Help Me. Thanks in Advance.
Here is my audio player code.
================>>
NSURL *url =[[NSURL alloc] initWithString:#"My Url"];
xPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
xPlayer.numberOfLoops = 0;
xPlayer.volume = 1.0f;
[xPlayer prepareToPlay];
[xPlayer play];
Q: Does the AVAudioPlayer provide support for streaming audio content?
A: The AVAudioPlayer class does not provide support for streaming audio based on HTTP URL's. The URL used with initWithContentsOfURL: must be a File URL (file://). That is, a local path.
Source: https://developer.apple.com/library/ios/qa/qa1634/_index.html
I want to play a radio station when someone presses the play radio button. However, it does not work.
Here is my code:
NSURL *url = [NSURL URLWithString:#"http://www.radio.net.pk/"];
NSData *data = [NSData dataWithContentsOfURL:url];
AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithData:data error:nil];
[audio play];
The AVAudioPlayer class only lets you play sound in any audio format available in iOS and OS X
This means, the AVAudioPlayer class does not provide support for streaming audio based on HTTP URL's. The URL used with initWithContentsOfURL: must be a local path URL.
So you should save the NSData locally (with different chunks) and play it using AVAudioPlayer.
It won't work ever.
Does radio.net.pk offers any APIs?
datWithContentsOfURL will return HTML string that you are trying to play using AVAudioPlayer !!. Please go through the website again and check for any developer API.
// Using this Cannel
NSURL *url6 = [NSURL URLWithString:#"http://sc6.spacialnet.com:35464/"]
layerItem = [AVPlayerItem playerItemWithURL:_strTemp]; // add url to playerItem
player = [AVPlayer playerWithPlayerItem:playerItem]; // add player item to AVAudioPlayer
player = [AVPlayer playerWithURL:_strTemp]
I've developed an iOS app that plays two separate audio streams simultaneously. To do this I am using AVPlayer thus:
//Use URL to set up the speech radio player.
NSURL *urlStreamSpeech = [NSURL URLWithString:self.urlAddressSpeech];
playerSpeech = [AVPlayer playerWithURL:urlStreamSpeech];
//Use URL to set up the music player.
NSURL *urlStreamMusic = [NSURL URLWithString:self.urlAddressMusic];
playerMusic = [AVPlayer playerWithURL:urlStreamMusic];
I am now trying to implement a volume control so that the user will be able to control the volume for the audio streams individually. As I've tried this I have come to the conclusion that there is no volume property for the AVPlayer class. I also looked at the AVAudioPlayer class, but from what I gather that class is only able to play local audio files, not streamed audio.
So my question is: how can I control the volume of streamed audio on iOS?
NSString* resourcePath = url; //your url
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
NSError *error;
app.audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
app.audioPlayer.numberOfLoops = 0;
app.audioPlayer.volume = 1.0f;
[app.audioPlayer prepareToPlay];
if (app.audioPlayer == nil)
NSLog(#"%#", [error description]);
else
[app.audioPlayer play];
Look into the AVPlayer class, part of the AVFoundation framework... this is the objective-c (iOS) class you use for streaming audio.
look at this post Live streaming
MPMusicPlayerController* musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
[musicPlayer setVolume:[SliderVolumen value]];
Only work in the device, no simulator.
Compatible with AVPlayer.