0

I am trying to play URL audio with AVPlayer. When I put a URL with .mp3 extension, it's working fine. but when I used a URL with no extension. it's not worked. Here's URL

Here's Code.

 let url = URL(string: "https://redirector.googlevideo.com/videoplayback?ipbits=0&mn=sn-xcvoxoxu-aixe%2Csn-npoeen7k&ip=117.53.42.8&mm=31%2C29&ms=au%2Crdu&mv=m&mt=1547352278&id=o-AIUfw7X-7-vO4ebqBskvYlVvVmhmgp9WJBItzTwZ7c51&keepalive=yes&pl=24&source=youtube&fvip=6&requiressl=yes&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&itag=250&gir=yes&clen=4252061&txp=5511222&dur=490.541&lmt=1540081943361780&ei=G7k6XNuzA9TNVv6RjvgI&expire=1547373947&c=WEB&key=yt6&mime=audio%2Fwebm&initcwndbps=143750&signature=774AA79C717B4D9AC6A68743C5730CCBF6A8B9B4.0D91F9D2F80CF12A6623D260B9FC5BB3E69BBAE1&title=Coke-Studio-Season-10-Latthay-Di-Chaadar-Quratulain-Balouch-Farhan-Saeed")
    let playerItem:AVPlayerItem = AVPlayerItem(url: url!)
    player = AVPlayer(playerItem: playerItem)

    if player?.rate == 0
    {
        player.play()
    } else {
        player.pause()
    }

Is there any other way to play audio in iOS with URL's that do not contains .mp3 or any other extension. I don't know why the player is not playing the audio file, there is no sound output on the device and there is no error shown.

6
  • 1
    Providing redirecting url could be an issue. Try exact url. Although your code is completely fine.
    – Kamran
    Jan 13, 2019 at 5:14
  • is there any other way to play audio using such a URL? Jan 13, 2019 at 5:20
  • You may check this stackoverflow link. You need to specify file type. stackoverflow.com/q/5501670/2641380
    – SHS
    Jan 13, 2019 at 5:38
  • I suspect the url is not a valid. For some reason i couldn't even play on browser(mobile).
    – Kamran
    Jan 13, 2019 at 5:48
  • link is fine @Kamran Jan 13, 2019 at 6:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.