How to lock media content for members-only access with Unlock
In this tutorial, we will see how to create a simple HTML and JavaScript page to lock media content (audio or video) so that only the creators' members can play it.
Unlock makes it easy for creators to monetize their work by only allowing their members to access some of their work. In this tutorial, we will see how to create a simple HTML and JavaScript page to lock media content (audio or video) so that only the creators' members can play it. Non-members will be able to see a small preview before being prompted to unlock the rest of the video.
Create a lock
The first step is to create a lock. For this, refer to this article. Once the lock is deployed, keep track of its address and network as we'll use them next.
Create the web document
In this example, we want to lock up access to this video.
HTML5 actually makes it very easy to embed any video in a document. Here's what it takes:
Loading and configuring Unlock for the page
For any web page which includes a lock, we use the same approach. First, we load the Paywall script, and then, we set the configuration for it.
Locking the video
JavaScript provides us with an API to control the video. We can use that to lock its access. The following sample provides details of how this can work. Note there are multiple ways of doing this; feel free to tinker around!
After this, you are all done!
Note: This tutorial implements a front-end locking approach, which is possible to circumvent; a determined actor could tinker with the JavaScript console of their web browser and inspect the code to find a workaround. It is absolutely possible to address this using an approach that is more difficult to circumvent, but that requires a back-end integration, which is more advanced and is outside the scope of this tutorial.
Last updated