4

My iOS app is going to have private and public videos, and users can purchase private ones. Right now I'm using YouTube and the youtube-ios-player-helper library for video hosting. Loading a public video is extremely easy:

playerView.loadWithVideoId("M7lc1UVf-VE")

but how do you do it in the most simplistic way for private videos? Is there something as simple as:

let playerVars = [
    "username": username,
    "password": password,
]
playerView.loadWithVideoId("M7lc1UVf-VE", playerVars: playerVars)

or something equally as simple?

JAL
  • 41,701
  • 23
  • 172
  • 300
rigdonmr
  • 2,662
  • 3
  • 26
  • 40
  • Please don't ask for libraries or other off-site resources. Those kinds of questions are off-topic for Stack Overflow. – JAL Jun 02 '16 at 20:44
  • Hey rigdonmr any updates? Let me know if my answer helped or you have any follow-up questions. – JAL Jun 06 '16 at 20:13
  • I have another question but u may think it's "off-topic" :( – rigdonmr Jun 07 '16 at 03:28
  • What is the question? Ask it in the comment and [review the help center](http://stackoverflow.com/help/) to see if it is on-topic. – JAL Jun 07 '16 at 11:36
  • I was wondering if there was a "go-to" library many people use for this kind of functionality. Maybe AWS Cloudfront? – rigdonmr Jun 07 '16 at 15:10
  • What functionality? For hiding videos privately and restricting them to IAP/specific email addresses? – JAL Jun 07 '16 at 15:11
  • Essentially for exactly what the YouTube library does but with private video functionality too – rigdonmr Jun 07 '16 at 15:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/114046/discussion-between-rigdonmr-and-jal). – rigdonmr Jun 07 '16 at 15:16
  • I replied to your chat message. – JAL Jun 08 '16 at 14:39

1 Answers1

1

If you look at the YouTube Embedded Players and Player Parameters API Documentation, you will see that there is no way to pass in a user's credentials.

The only way to play private videos in a web view like the YTPlayerView helper class is to take control of the web view and have the user log into their YouTube account, and then play back the Private video in that specific web view session only. YouTube suggests marking videos as Unlisted rather than Private for playback on mobile devices.

Related discussion can be found in this similar question about the Android player and this Google Groups post.

Community
  • 1
  • 1
JAL
  • 41,701
  • 23
  • 172
  • 300
  • Do you know if there are potential problems with the unlisted approach? Couldn't someone get the video id from the unlisted video and share it with everyone, and now everyone has that id that they can put in the URL? – rigdonmr Jun 02 '16 at 23:06
  • @rigdonmr Traditionally, only way that anyone would be able to get the URL is if you gave it to them directly. As with any web request, it's possible someone could be sniffing the request or using a Jailbroken device and get the URL. But if you're relying on YouTube for security, I think you're using the wrong video platform. Can you elaborate a little more on your use case? – JAL Jun 02 '16 at 23:10
  • So there is a library of videos on my app. Some will be free, which are public videos; and some will cost money, which I was hoping I could use private videos with a key for that (the user obtains a key when they buy the video), but as you said, it's not in the API. What I'm worried about with unlisted videos is that it's not actually private, more like hidden, but for a relatively small scale app, does that matter? – rigdonmr Jun 02 '16 at 23:17
  • @rigdonmr I see no major security flaws with your use case. Unlisted videos should work, and you can always rotate the Video IDs you use every few months if you see some get leaked. Worst comes to worst, you could require that your user log into their YouTube account in the webview before showing any Private videos. I'm not sure how that would work, as you wouldn't get a login callback. – JAL Jun 03 '16 at 03:11
  • YouTube has unfortunately made this really hard. You could always use an alternate host, or break YouTube's terms of service and play the videos back in an `AVPlayer` or something by getting the direct MP4 link from the video's manifest. I would not recommend that though. – JAL Jun 03 '16 at 03:12