diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java index 281871fe1f8..34b536b0846 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java @@ -44,7 +44,7 @@ import com.google.android.exoplayer2.util.Util; import com.vocabimate.protocol.AesEncryptionUtil; import com.vocabimate.protocol.ILicenceTo; -import com.vocabimate.helpers.LicenceBody; +import com.google.android.exoplayer2.demo.helpers.LicenceBody; import java.io.IOException; import java.io.InputStream; @@ -167,7 +167,7 @@ public ILicenceTo getKeyHelper(long videoId, UriSample sample, String localEncKe // While Playing if(sample.uri.toString().contains("vid5_seg")) { - return new LicenceBody(75, 20, "N", + return new LicenceBody("vid5_seg", 75, 20, "N", "http://54.152.186.92:60801/drm/videoServer/Video/inayat/vid5_seg/playlist.m3u8", TOKEN, "http://54.152.186.92:60801/license/create_license", localEncKey, localEncIV @@ -175,7 +175,7 @@ public ILicenceTo getKeyHelper(long videoId, UriSample sample, String localEncKe } if(sample.uri.toString().contains("vid3_seg")) - return new LicenceBody(75, 18, "N", + return new LicenceBody("vid3_seg", 75, 18, "N", "http://54.152.186.92:60801/drm/videoServer/Video/inayat/vid3_seg/playlist.m3u8", TOKEN, "http://54.152.186.92:60801/license/create_license", localEncKey, localEncIV @@ -184,7 +184,7 @@ public ILicenceTo getKeyHelper(long videoId, UriSample sample, String localEncKe if(sample.uri.toString().contains("vid2_seg")) - return new LicenceBody(75, 1, "N", + return new LicenceBody("vid2_seg", 75, 1, "N", "http://54.152.186.92:60801/drm/videoServer/Video/inayat/vid2_seg/playlist.m3u8", TOKEN, "http://54.152.186.92:60801/license/create_license", localEncKey, localEncIV diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/Licence.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/Licence.java new file mode 100644 index 00000000000..81660fd57c0 --- /dev/null +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/Licence.java @@ -0,0 +1,153 @@ +package com.google.android.exoplayer2.demo.helpers; + +import com.vocabimate.protocol.ILicenceContract; + +import java.io.Serializable; +import java.util.Date; + +/** + * Created by Hisham on 29/Oct/2018 - 21:08 + */ +public class Licence implements ILicenceContract, Serializable { + + private int userId; + private int videoId; + private String decryptionKey; + private Date validateDt; + private Date createDt; + private String createUserId; + private Date updateDt; + private String updateUserId; + private String delInd; + private long expTime;//long videoOfflineExpiryTime(); + private long serverTime;// long serverTime(); + private VideoSubscription videoSubscription; + private int gracePeriod; //long gracePeriodInMillis(); + private long videoProviderExpiryTime;//long videoProviderExpiryTime(); + + + public int getGracePeriod() { + return gracePeriod; + } + + public void setGracePeriod(int gracePeriod) { + this.gracePeriod = gracePeriod; + } + + public int getUserId() { + return userId; + } + + public void setUserId(int userId) { + this.userId = userId; + } + + public int getVideoId() { + return videoId; + } + + public void setVideoId(int videoId) { + this.videoId = videoId; + } + + public Date getValidateDt() { + return validateDt; + } + + public void setValidateDt(Date validateDt) { + this.validateDt = validateDt; + } + + public Date getCreateDt() { + return createDt; + } + + public void setCreateDt(Date createDt) { + this.createDt = createDt; + } + + public String getCreateUserId() { + return createUserId; + } + + public void setCreateUserId(String createUserId) { + this.createUserId = createUserId; + } + + public Date getUpdateDt() { + return updateDt; + } + + public void setUpdateDt(Date updateDt) { + this.updateDt = updateDt; + } + + public String getUpdateUserId() { + return updateUserId; + } + + public void setUpdateUserId(String updateUserId) { + this.updateUserId = updateUserId; + } + + public String getDelInd() { + return delInd; + } + + public void setDelInd(String delInd) { + this.delInd = delInd; + } + + public String getDecryptionKey() { + return decryptionKey; + } + + public long getVideoProviderExpiryTime() { + return videoProviderExpiryTime; + } + + public void setVideoProviderExpiryTime(long videoProviderExpiryTime) { + this.videoProviderExpiryTime = videoProviderExpiryTime; + } + + public void setDecryptionKey(String decryptionKey) { + this.decryptionKey = decryptionKey; + } + + public long getExpTime() { + return expTime; + } + + public void setExpTime(long expTime) { + this.expTime = expTime; + } + + + + public void setServerTime(long serverTime) { + this.serverTime = serverTime; + } + + public long getServerTime() { + return serverTime; + } + + public VideoSubscription getVideoSubscription() { + return videoSubscription; + } + + public void setVideoSubscription(VideoSubscription videoSubscription) { + this.videoSubscription = videoSubscription; + } + + @Override + public String toString() { + return "LicenseFile [userId=" + userId + ", videoId=" + videoId + ", decryptionKey=" + decryptionKey + + ", validateDt=" + validateDt + ", createDt=" + createDt + ", createUserId=" + createUserId + + ", updateDt=" + updateDt + ", updateUserId=" + updateUserId + ", delInd=" + delInd + ", expTime=" + + expTime + ", serverTime=" + serverTime + ", videoSubscription=" + videoSubscription + "]"; + } + + + +} diff --git a/protocol/src/main/java/com/vocabimate/helpers/LicenceBody.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/LicenceBody.java similarity index 55% rename from protocol/src/main/java/com/vocabimate/helpers/LicenceBody.java rename to demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/LicenceBody.java index 4c56c016a0e..73ad06fd099 100644 --- a/protocol/src/main/java/com/vocabimate/helpers/LicenceBody.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/LicenceBody.java @@ -1,4 +1,4 @@ -package com.vocabimate.helpers; +package com.google.android.exoplayer2.demo.helpers; import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; @@ -13,45 +13,45 @@ public class LicenceBody extends KeyHelper implements Serializable { @SerializedName("licenseTO") - private LicenceBodyInternal licenceBodyInternal; + private LicenceBody.LicenceBodyInternal licenceBodyInternal; + private String videoName; - public LicenceBody(int userId, int videoId, String delInd, String m3u8Path, String token, String licenceUrl, String localEncryptionKey, String localEncryptionIV) { + public LicenceBody(String videoName, int userId, int videoId, String delInd, String m3u8Path, String token, String licenceUrl, String localEncryptionKey, String localEncryptionIV) { super(m3u8Path, token, licenceUrl, localEncryptionKey, localEncryptionIV); - licenceBodyInternal = new LicenceBodyInternal(userId, videoId, delInd); + this.licenceBodyInternal = new LicenceBody.LicenceBodyInternal(userId, videoId, delInd); + this.videoName = videoName; } - @Override + public String getVideoName() { + return videoName; + } + + public String jsonBody() { - return new Gson().toJson(this); + return (new Gson()).toJson(this); } - @Override public String getRequestType() { return "POST"; } public int getVideoId() { - return licenceBodyInternal.videoId; + return this.licenceBodyInternal.videoId; } public int getUserId() { - return licenceBodyInternal.userId; + return this.licenceBodyInternal.userId; } - /** - * @return Unique key path to append for every video ex: vcb://{videoId} that will become- vcb://18 or vcb://360p.m3u8/18, just it should be unique - */ - @Override public String getUniqueKeyPathForVCB() { - return String.valueOf(licenceBodyInternal.videoId); + return String.valueOf(this.licenceBodyInternal.videoId); } - @Override public Class getLicenceResponseModelClass() { return LicenceModel.class; } - private class LicenceBodyInternal implements Serializable { + public class LicenceBodyInternal implements Serializable { @SerializedName("userId") int userId; @SerializedName("videoId") @@ -59,10 +59,10 @@ private class LicenceBodyInternal implements Serializable { @SerializedName("delInd") String delInd; - /* package */ LicenceBodyInternal(int userId, int videoId, String delInd) { + LicenceBodyInternal(int userId, int videoId, String delInd) { this.userId = userId; this.videoId = videoId; this.delInd = delInd; } } -} +} \ No newline at end of file diff --git a/protocol/src/main/java/com/vocabimate/helpers/LicenceModel.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/LicenceModel.java similarity index 64% rename from protocol/src/main/java/com/vocabimate/helpers/LicenceModel.java rename to demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/LicenceModel.java index 51cc3a6c3f2..ca2b3acbc1a 100644 --- a/protocol/src/main/java/com/vocabimate/helpers/LicenceModel.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/LicenceModel.java @@ -1,23 +1,26 @@ -package com.vocabimate.helpers; +package com.google.android.exoplayer2.demo.helpers; import com.google.gson.annotations.SerializedName; import com.vocabimate.protocol.ILicenceWrapperContract; +import java.io.Serializable; + /** * Created by Hisham on 16/Oct/2018 - 14:27 */ -public class LicenceModel implements ILicenceWrapperContract { - +public class LicenceModel implements ILicenceWrapperContract, Serializable { @SerializedName("licenseFile") private Licence licenseFile; + public LicenceModel() { + } + public Licence getLicenseFile() { - return licenseFile; + return this.licenseFile; } public LicenceModel setLicenseFile(Licence licenseFile) { this.licenseFile = licenseFile; return this; } - } diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/VideoSubscription.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/VideoSubscription.java new file mode 100644 index 00000000000..1f06b6e4dc1 --- /dev/null +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/helpers/VideoSubscription.java @@ -0,0 +1,42 @@ +package com.google.android.exoplayer2.demo.helpers; + +import java.io.Serializable; + +/** + * Created by Hisham on 01/Nov/2018 - 19:48 + */ +public class VideoSubscription implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + private Long startDate; + private Long endDate;// long subscriptionEndTime(); + public VideoSubscription() { + super(); + } + + public VideoSubscription(Long startDate, Long endDate) { + super(); + this.startDate = startDate; + this.endDate = endDate; + } + public Long getStartDate() { + return startDate; + } + public void setStartDate(Long startDate) { + this.startDate = startDate; + } + + public Long getEndDate() { + return endDate; + } + public void setEndDate(Long endDate) { + this.endDate = endDate; + } + + @Override + public String toString() { + return "VideoSubscription [startDate=" + startDate + ", endDate=" + endDate + "]"; + } +} diff --git a/protocol/src/main/java/com/vocabimate/helpers/Licence.java b/protocol/src/main/java/com/vocabimate/helpers/Licence.java deleted file mode 100644 index 357d9b986e9..00000000000 --- a/protocol/src/main/java/com/vocabimate/helpers/Licence.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.vocabimate.helpers; - -import com.vocabimate.protocol.ILicenceContract; - -import java.util.Date; - -/** - * Created by Hisham on 29/Oct/2018 - 21:08 - */ -public class Licence implements ILicenceContract { - - private int userId; - private int videoId; - private String decryptionKey; - private Date validateDt; - private Date createDt; - private String createUserId; - private Date updateDt; - private String updateUserId; - private String delInd; - - public Licence() { //no operation - } - - public Licence(int userId, int videoId) { - super(); - this.userId = userId; - this.videoId = videoId; - } - - public Licence(int userId, int videoId, Date validateDt, Date createDt, String createUserId, Date updateDt, String updateUserId, String delInd) { - super(); - this.userId = userId; - this.videoId = videoId; - this.validateDt = validateDt; - this.createDt = createDt; - this.createUserId = createUserId; - this.updateDt = updateDt; - this.updateUserId = updateUserId; - this.delInd = delInd; - } - - public int getUserId() { - return userId; - } - - public void setUserId(int userId) { - this.userId = userId; - } - - public int getVideoId() { - return videoId; - } - - public void setVideoId(int videoId) { - this.videoId = videoId; - } - - public Date getValidateDt() { - return validateDt; - } - - public void setValidateDt(Date validateDt) { - this.validateDt = validateDt; - } - - public Date getCreateDt() { - return createDt; - } - - public void setCreateDt(Date createDt) { - this.createDt = createDt; - } - - public String getCreateUserId() { - return createUserId; - } - - public void setCreateUserId(String createUserId) { - this.createUserId = createUserId; - } - - public Date getUpdateDt() { - return updateDt; - } - - public void setUpdateDt(Date updateDt) { - this.updateDt = updateDt; - } - - public String getUpdateUserId() { - return updateUserId; - } - - public void setUpdateUserId(String updateUserId) { - this.updateUserId = updateUserId; - } - - public String getDelInd() { - return delInd; - } - - public void setDelInd(String delInd) { - this.delInd = delInd; - } - - public String getDecryptionKey() { - return decryptionKey; - } - - public void setDecryptionKey(String decryptionKey) { - this.decryptionKey = decryptionKey; - } - - -} diff --git a/protocol/src/main/java/com/vocabimate/protocol/VocabimateHttpUrlConnection.java b/protocol/src/main/java/com/vocabimate/protocol/VocabimateHttpUrlConnection.java index 872048aaeb2..b72d41a8909 100644 --- a/protocol/src/main/java/com/vocabimate/protocol/VocabimateHttpUrlConnection.java +++ b/protocol/src/main/java/com/vocabimate/protocol/VocabimateHttpUrlConnection.java @@ -35,7 +35,6 @@ public VocabimateHttpUrlConnection(URL url) throws IOException { @Override public void connect() throws IOException { - // todo Need to fix things here, not getting token and licenceTo url on older phones. String licence_url = licenceTo.getLicenceUrl();//getRequestProperty("licence_url"); String token = licenceTo.getToken();//getRequestProperty("access_token"); // if (licence_url == null) { @@ -70,16 +69,18 @@ public void connect() throws IOException { InputStream stream; if (licenceWrapper != null) { ILicenceContract licenseFile = licenceWrapper.getLicenseFile(); + if(licenseFile == null){ + connected = false; + responseCode = 500; + return; + } if(licenceTo instanceof KeyHelper) { ((KeyHelper)licenceTo).setLicence(licenseFile); } - if(licenseFile != null && licenseFile.getDecryptionKey() != null) { + if(licenseFile.getDecryptionKey() != null) { TokenDecryptionHelper tokenDecryptionHelper = new TokenDecryptionHelper(token, licenseFile.getDecryptionKey()); byte[] decrypt = tokenDecryptionHelper.decrypt(); stream = new ByteArrayInputStream(decrypt); -// for (int i = 0; i < decrypt.length; i++) { -// buffer[i] = decrypt[i]; -// } vocAbsInputStream.setInputStream(stream); } } @@ -98,7 +99,7 @@ private String readStream(InputStream in) { StringBuffer response = new StringBuffer(); try { reader = new BufferedReader(new InputStreamReader(in)); - String line = ""; + String line; while ((line = reader.readLine()) != null) { response.append(line); }