Giter Club home page Giter Club logo

jwplatform-java's Introduction

JW Platform API Client

The JWPlatform library provides convenient access to the JW Platform Management API from applications written in the Java language.

Visit JW Player Developer site for more information about JW Platform API.

Requirements

Java 8 and later.

Install With Maven:

Add this dependency to your project's POM:

<dependency>
  <groupId>com.jwplayer</groupId>
  <artifactId>jwplatform</artifactId>
  <version>1.1.0</version>
</dependency>

V2 Client

Usage

The following is an example of how to use the V2 client, MediaClient, used to access all media v2 api routes:

import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import com.jwplayer.jwplatform.client.MediaClient;
import com.jwplayer.jwplatform.exception.JWPlatformException;

public class Example {

	public static void main(String[] args) {
		String apiSecret = "secret";

		try {
			MediaClient client = MediaClient.getClient(apiSecret);

			// Query params
			Map<String, String> params = new HashMap<>();
			params.put("page_length", "10");
			JSONObject listMediaResponse = client.listAllMedia("yourSiteId", params);
			System.out.println(listMediaResponse);

			// Show the list of media for the site Id
			JSONArray media = (JSONArray) listMediaResponse.getJSONArray("media");
			System.out.println(media);
		} catch (JWPlatformException e) {
			e.printStackTrace();
		}
	}
}

V1 Client

The V1 Client remains available for use, but is deprecated. We strongly recommend using the V2 Client.

Usage

The following is an example of how to use the V1 client for a video of sourcetype url:

import com.jwplayer.jwplatform.v1.JWPlatformClient;
import com.jwplayer.jwplatform.exception.JWPlatformException;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;

public class JWPlatformClientExample {

    public static void main(String[] args) {
        String apiKey = "key";
        String apiSecret = "secret";

        String videosCreatePath = "videos/create";
        Map<String, String> videosCreateParams = new HashMap<>();
        videosCreateParams.put("sourcetype", "url");
        videosCreateParams.put("sourceformat", "mp4");
        videosCreateParams.put("sourceurl", "http://www.some-url.com/some-video.mp4");
        videosCreateParams.put("title", "Some Video Title");

        String videosShowPath = "/videos/show";
        
        try {            
            JWPlatformClient client = JWPlatformClient.create(apiKey, apiSecret);
            
            // Create a video asset
            JSONObject videosCreateResponse = client.request(videosCreatePath, videosCreateParams);
            System.out.println(videosCreateResponse);
            
            // Show the properties of the created video
            String videoKey = videosCreateResponse.getJSONObject("video").getString("key");
            Map<String, String> videosShowParams = new HashMap<>();
            videosShowParams.put("video_key", videoKey);
            JSONObject videosShowResponse = client.request(videosShowPath, videosShowParams);
            System.out.println(videosShowResponse);
        } catch (JWPlatformException e) {
            e.printStackTrace();
        }
    }
}

The following is an example of how to use the client for a video of sourcetype file:

import com.jwplayer.jwplatform.JWPlatformClient;
import com.jwplayer.jwplatform.exception.JWPlatformException;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;

public class JWPlatformClientExample {

    public static void main(String[] args) {
    String apiKey = "key";
    String apiSecret = "secret";

    String videosCreatePath = "/videos/create";
    Map<String, String> videosCreateParams = new HashMap<>();
    videosCreateParams.put("sourcetype", "file");
    videosCreateParams.put("title", "Some Video Title");

    String localFilePath = "/some/path/test_video.mp4";

    try {
        JWPlatformClient client = JWPlatformClient.create(apiKey, apiSecret);

        // Create a video asset
        JSONObject videosCreateResponse = client.request(videosCreatePath, videosCreateParams);
        System.out.println(videosCreateResponse);

        // Upload the video from local file system
        JSONObject videoUploadResponse = client.upload(videosCreateResponse, localFilePath);
        System.out.println(videoUploadResponse);
    } catch (JWPlatformException e) {
        e.printStackTrace();
    }
}

Note

In the preceding V1 example snippets, all URL paths feature a leading slash. These must be included for the URL builder to work properly.

Supported operations

All API methods documented in our api documentation are available in this client. Please refer to our api documentation.

ChangeLog

See the Change Log for recent changes.

License

JW Platform API library is distributed under the Apache 2 license.

jwplatform-java's People

Contributors

dvfeinblum avatar shwetamurthy20 avatar swhelan091 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.