-1

我尝试从服务器 url 播放音频但没有播放,但我尝试从文档目录路径 url 播放音频并且播放正常。

NSData *songData=[NSData dataWithContentsOfURL:[NSURL URLWithString:
[NSString stringWithFormat:@"%@",aSongURL]]];
AVAudioPlayer *abc = [[AVAudioPlayer alloc] initWithData:songData error:nil];
abc.numberOfLoops=0;
[abc prepareToPlay];
[abc play];
4

2 回答 2

1

你可以试试这个。希望能帮助到你。

AVPlayer *objAVPlayer = [[AVPlayer alloc] initWithURL:url];
[objAVPlayer play];
于 2017-05-25T11:59:06.767 回答
0

我的答案如下

视图控制器.h

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

@interface ViewController : UIViewController
@property (nonatomic,strong)AVAudioPlayer *player;
- (IBAction)actionPlayAudio:(id)sender;
@end

视图控制器.m

#import "ViewController.h"

@interface ViewController ()
@end
@implementation ViewController
@synthesize player;

- (void)viewDidLoad {
    [super viewDidLoad];
}
- (IBAction)actionPlayAudio:(id)sender {
    NSString *strAudioFileURL = @"dev.epixelsoft.co/love_app/audio/img_14957068361.caf";
    NSURL *soundFileURL = [NSURL fileURLWithPath:strAudioFileURL];
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
    [player play];
}
于 2017-05-25T15:34:39.410 回答