Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't play mp3 file over HTTP via AVPlayer

Tags:

ios

avplayer

I'm trying to play MP3 file via AVPlayer:

let url = URL(string: "http://transom.org/wp-content/uploads/2004/03/stereo_40kbps.mp3?_=7")!
let asset = AVURLAsset(url: url)
let item = AVPlayerItem(asset: asset)
let player = AVPlayer(playerItem: item)
player.play()

But I'm getting the next log:

2017-09-26 21:57:07.906598+0300 MyApp[7558:1177816] CredStore - performQuery - Error copying matching creds.  Error=-25300, query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    "r_Attributes" = 1;
    sync = syna;
}

I guess it's because of iOS 11 and Xcode 9, but I have no idea how to solve this problem.

like image 963
Alexander Perechnev Avatar asked Sep 26 '17 19:09

Alexander Perechnev


2 Answers

same error.
I've solved with server-side work.
remove HSTS header "Strict-Transport-Security: max-age=31536000" from http response, disappear error and work fine. I don't know the cause..
request : https://abc.../aaaa.mp3

like image 45
modeverv Avatar answered Nov 13 '22 16:11

modeverv


The problem seems to be with the App Transport security, after enabling it, it worked fine with the following sets of code in iOS 11,
Also the above URL that you have provided seems to have associated https link, please use either https link or allow App Transport security

let avPlayerVC = AVPlayerViewController()
        let url = URL(string: "https://transom.org/wp-content/uploads/2004/03/stereo_40kbps.mp3?_=7")!
        let asset = AVURLAsset(url: url)
        let item = AVPlayerItem(asset: asset)
        let player = AVPlayer(playerItem: item)
        avPlayerVC.player = player

        present(avPlayerVC, animated: true) {
            player.play()
        }

But here I have used AVPlayerViewController and used the same instance of AVPlayer as you used in your code.
I don't know how you are using the AVPlayer in your case, but the above case worked fine.

like image 76
Bharath Avatar answered Nov 13 '22 17:11

Bharath