Search code examples
iosfacebookvideouiwebviewavplayer

Swift : Play a Facebook Video using an AVPlayer


I need to play videos from several video sources (Facebook & Instagram) for my iOS app.

I create an AVPlayerItem with the video URL and it's work for Instagram but not for facebook.

URLs layout are as following :

Instagram :

https://scontent.cdninstagram.com/t50.2886-16/xxx.mp4



Facebook :

https://www.facebook.com/video/embed?video_id=xxx


Is there a way to play Facebook videos in AVPlayer or should I use UIWebview?


Solution

  • The problem was the way how I recovered the video.

    The following URL allow recovering an iFrame, not a playable file https://www.facebook.com/video/embed?video_id=xxx


    According to Facebook Video API, you can get "A URL to the raw, playable video file" with "source" field.


    I made a test call with Postman. You can see the correct URL highlighted which can be used successfully in AVPlayer.enter image description here