AVPlayer无法播放实时广播URL

时间:2018-11-16 05:20:45

标签: ios avplayer

我的实时广播URL是http://s2.yesstreaming.net:7091/stream,并且AVPlayer无法播放。

这是现场广播音频。

这是我的代码。

let OKAction = UIAlertAction(title: "OK", style: .default, handler:
    {
        (action: UIAlertAction!) ->Void in
        let textfield = alert.textFields![0] as UITextField
        newTeacherName = textfield.text!.uppercased()
        if !(newTeacherName.isEmpty)
        {
            //checking if teacher already exists using function teacherExists
            let exists = self.teacherExists(teacherName: newTeacherName, completion:

            if exists == true //if duplicate teacher is found
            {
                let alert = UIAlertController(title: "Duplicate Teacher", message: "Teacher \(newTeacherName) has been added earlier", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                self.present(alert, animated: true, completion: nil)
            }
            else
            {
                //add teacher to database here
                let dict = ["teacher_name" : newTeacherName]
                let newTeacher = Teacher(dictionary: dict)
                let tableRef = self.dataBaseRef.child("teachers") //getting reference of node with name teachers
                let recordRef = tableRef.childByAutoId() //creating a new record in teachers node
                recordRef.setValue(newTeacher!.toDictionary())//adding data to new record in teachers node
            }
        }
    })

错误是:

@interface ViewController () {
    AVPlayer *player;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive:true error:nil];
    // Do any additional setup after loading the view, typically from a nib.
    player = [[AVPlayer alloc] init];
}

-(void)viewDidAppear:(BOOL)animated {
    AVPlayer *player123 = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:@"http://s2.yesstreaming.net:7091/stream"]];
    player.allowsExternalPlayback = true;
    player = player123;
}

- (IBAction)btnPayPauseAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected) {
        [player play];
    } else {
        [player pause];
    }
}
@end

0 个答案:

没有答案