I want to play a music file using URL Link in the iPhone. But when I use the below code I am getting error I am not getting where I am going wrong. Can anyone Correct me?
-(void)viewDidLoad
{
[super viewDidLoad];
NSString* resourcePath = @"http://192.167.1.104:8888/SHREYA.mp3"; //your url
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:_objectData error:&error];
audioPlayer.numberOfLoops = -1;
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
}
Browse and play your musicIn the Music app, tap Library, then tap a category, such as Albums or Songs; tap Downloaded to view only music stored on iPhone.
Touch and hold the folder or file. , tap Manage Shared Folder or Manage Shared File, then tap Send Link. Choose a method for sending the link, enter any other requested information, then send or post the invitation.
This should work:
NSURL *url = [NSURL URLWithString:@"<#Live stream URL#>];
// You may find a test stream at <http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8>.
self.playerItem = [AVPlayerItem playerItemWithURL:url];
//(optional) [playerItem addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext];
self.player = [AVPlayer playerWithPlayerItem:playerItem];
self.player = [AVPlayer playerWithURL:<#Live stream URL#>];
//(optional) [player addObserver:self forKeyPath:@"status" options:0 context:&PlayerStatusContext];
Use the following code to play the music:
[self.player play];
Try the following:
-(void)viewDidLoad
{
[super viewDidLoad];
NSString* resourcePath = @"your url"; //your url
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
audioPlayer.numberOfLoops = 1;
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With