DEV Community

Cover image for How to quickly setup a continue watching endpoint for your video players

How to quickly setup a continue watching endpoint for your video players

In this blog post we will walk through how you can quickly setup a continue watching micro service for your video player applications using Open Source Cloud and Redis Cloud.

Today a user of a video streaming service expects to be able to pick up where they left off, on any of the episodes they watched and on any of the devices they have. To handle that you would need to develop a backend service with endpoints for the video player and device application to write to and read from.

Open Source Cloud by Eyevinn Technology is a service that enables you to build software solutions on on open and detachable ready-to-run cloud components based on open source, and where revenue from this service is contributed back to the open source community.

Redis Cloud is the easiest way to build and manage fast, scalable apps–fast. It reduces total cost of ownership and helps organizations fight database sprawl. It also empowers architects and developers like no other cloud-based service.

In this post we will create a continue watching service using one of the available components in Open Source Cloud and Redis Cloud for storage. As both components are based on open source there is nothing preventing you from bringing these components "home" to your own infrastructure.

Create a database on Redis Cloud

Sign in (or sign up) on Redis Cloud, start a subscription and create a database.

Database on Redis Cloud

Once created a database note down the Public endpoint and port as seen above. You will also need the password that you find further down on the same page.

Create service on Open Source Cloud

Create an account on Open Source Cloud unless you already have one. Once logged in to Open Source Cloud you will look for the component called Continue Watching Service.

Service description
When you have started a subscription you can create a service by clicking on the "Create service button".

Create service menu item

When you have clicked this button you will be presented with a dialog where you will enter the connection details to the Redis database you created. Replace Host, Port and Password with the configuration details from your Redis database. Then click on Create.

Create modal

Wait a few seconds and you will see the service up and running.

Service running

Now your continue watching service is up and running and you can copy the endpoint URL available above and try the following in a new tab in your browser.

https://demo-jonas.eyevinn-continue-watching-api.auto.prod.osaas.io/position/jonas

This will give the saved positions for the user jonas and now it should be just an empty array.
To save a position your video player or application would issue an HTTP POST request to /position/jonas/12345/120 where 12345 is the id of the episode and 120 is the position in seconds. For example:

curl -v -X POST \
  -H 'x-jwt: Bearer <SAT>' \
  https://demo-jonas.eyevinn-continue-watching-api.auto.prod.osaas.io/position/jonas/12345/120
Enter fullscreen mode Exit fullscreen mode

And now when you retrieve the positions for user jonas you would get.

curl -v -X GET \
  -H 'x-jwt: Bearer <SAT>' \
  https://demo-jonas.eyevinn-continue-watching-api.auto.prod.osaas.io/position/jonas

[{"assetId":"12345","position":"120","expiration":31535812}]
Enter fullscreen mode Exit fullscreen mode

How to get the SAT (service access token) you can read about in the API documentation and the serviceId in this case is eyevinn-continue-watching.

curl -X 'POST' \
  'https://token.svc.prod.osaas.io/servicetoken' \
  -H 'accept: application/json' \
  -H 'x-pat-jwt: Bearer <PAT>' \
  -H 'Content-Type: application/json' \
  -d '{
  "serviceId": "eyevinn-continue-watching"
}'
Enter fullscreen mode Exit fullscreen mode

The PAT (personal access token) you find under Settings in the menu to the left.

And that's all you need to provide a continue watching micro service in your solution.

Top comments (0)