I am encountering an issue while trying to set up JW Player with DRM protection and DASH streaming. The setup involves fetching DRM keys from a remote server and using those keys to play a DASH stream. Here’s the setup I have:
<script src="https://content.jwplatform.com/libraries/KB5zFt7A.js"></script>
<div id="player"></div>
<script>
function fetchDRMKeys(callback) {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://yuvraj43.xyz/tp-keys/live/key.php?id=516', true);
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) {
try {
const response = JSON.parse(xhr.responseText);
if (Array.isArray(response.keys)) {
callback(null, response.keys);
} else {
callback('Error parsing response');
}
} catch (e) {
callback('Error parsing response');
}
} else {
callback('Error fetching keys');
}
};
xhr.onerror = function() {
callback('Network error');
};
xhr.send();
}
fetchDRMKeys(function(error, keys) {
if (error) {
console.error('Failed to fetch DRM keys:', error);
return;
}
const drmConfig = { clearkey: {} };
keys.forEach(key => {
if (key.kty === 'oct') {
drmConfig.clearkey[key.kid] = key.k;
}
});
jwplayer("player").setup({
playlist: [{
title: "Maa",
description: "Test",
image: "https://mediaready.videoready.tv/tatasky-epg/image/fetch/f_auto,fl_lossy,q_auto,h_250,w_250/https://ltsk-cdn.s3.eu-west-1.amazonaws.com/jumpstart/Temp_Live/cdn/HLS/Channel/imageContent-25361-jhsvr3nc-v1/imageContent-25361-jhsvr3nc-m1.png",
sources: [{
file: "https://yuvraj43.xyz/TP-worldwide/manifest.mpd?id=516",
type: "dash",
drm: {
clearkey: drmConfig.clearkey
}
}]
}],
width: "100%",
aspectratio: "16:9",
autostart: false,
cast: {},
playbackRateControls: true,
preload: "auto"
});
jwplayer().on('error', function(e) {
console.error('JW Player Error:', e);
});
jwplayer().on('setupError', function(e) {
console.error('JW Player Setup Error:', e);
});
});
</script>
Issue:
Network Errors:
1. I’m seeing errors related to DRM key fetching, and JW Player is not playing the video. Specifically, I receive a CORS error when attempting to fetch DRM keys.
2. JW Player Error Codes: The errors shown are related to the JW Player setup (Error 242600 and 342600).
Details:
The CORS issue occurs when fetching DRM keys from https://yuvraj43.xyz/tp-keys/live/key.php?id=516.
The MPD URL is https://yuvraj43.xyz/TP-worldwide/manifest.mpd?id=516.
I have verified that the keys.php works correctly in other players(ex. NS Player)
Questions:
How can I resolve the CORS issue for the DRM keys?
What could be causing the JW Player errors, and how can I fix them?
Any help or guidance would be greatly appreciated!