0

I've followed every resource that I can find, and I don't know why this isn't working. I'm trying to play it on the simulator. Also, I have verified that my urlString is accurate and that it plays when pasted into a browser. What am I missing?

.h file

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface MyViewController : UIViewController <AVAudioPlayerDelegate>

@end

.m file

@interface SessionsListViewController ()
@property (strong, nonatomic) AVAudioPlayer *audioPlayer;
@end

- (void) viewDidLoad
{
    NSString *urlString = [NSString stringWithFormat:@"%@%@", AUDIO_URL, @"test.mp3"];
    NSURL *url = [NSURL URLWithString:urlString];
    NSError *err = nil;
    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err];

    [self.audioPlayer prepareToPlay];
    [self.audioPlayer setDelegate:self];
     self.audioPlayer.volume = 1.0;
    [self.audioPlayer play];


}
AndroidDev
  • 20,466
  • 42
  • 148
  • 239
  • What does a log of url show? – rdelmar Aug 14 '14 at 22:30
  • Don't you need a "www" and/or an "http://" at the beginning of that? Browsers automatically add that for you, I don't think that's true for initWithContentsOfURL:. – rdelmar Aug 14 '14 at 22:38
  • Also, I think this is probably a typo, but there should be an @end after your property declaration in the class extension. – rdelmar Aug 14 '14 at 22:39
  • Yes. it's a typo. I've edited the post. – AndroidDev Aug 14 '14 at 22:41
  • That's a SO formatting thing. They took my text (which included http://www) and displayed it as a hyperlink without that part. Not sure why or how to correct it, but that full URL is in the string. – AndroidDev Aug 14 '14 at 22:42
  • I still can't get "h t t p : / / w w w ." to appear at the front! – AndroidDev Aug 14 '14 at 22:44
  • Here is the best answer to this: http://stackoverflow.com/questions/13131177/streaming-mp3-audio-with-avplayer – AndroidDev Aug 14 '14 at 23:08

0 Answers0