YoannLth YoannLth - 1 year ago 189
iOS Question

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 :


Facebook :


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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download