Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 960
YoannLth Avatar asked Sep 12 '16 13:09

YoannLth


1 Answers

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

like image 75
YoannLth Avatar answered Sep 29 '22 17:09

YoannLth