2016-01-29 16 views
5

Ho cercato di scoprire come determinare quale browser di sistema DRM sta utilizzando. E infatti, solo chrome dice che è 'com.widevine.alpha' usare IE & Safari (Win) errore di lancio su 'requestMediaKeySystemAccess', e firefox non prova nemmeno a dire che usa 'com.adobe.acccess' =]Determina il sistema DRM supportato dal browser

c'è qualche soluzione, come Modernizr o simile per ottenere quale keySystem I dovrebbe usare?

+0

controlla questo articolo che ho scritto di recente: http://aameer.github.io/articles/digital-rights-management-multi-drm/ spiega in dettaglio su come ottenere multi-drm, controlla la sezione about about stato attuale – Aameer

risposta

4

Ci sono diversi siti web che offrono tale verifica, come dash-player.com/browser-capabilities/ dopo aver dato un'occhiata più da vicino come è fatto, si può usare qualcosa di simile a:

// EME Check 
 
var keySystems = { 
 
    widevine: ['com.widevine.alpha'], 
 
    playready: ['com.microsoft.playready', 'com.youtube.playready'], 
 
    clearkey: ['webkit-org.w3.clearkey', 'org.w3.clearkey'], 
 
    primetime: ['com.adobe.primetime', 'com.adobe.access'], 
 
    fairplay: ['com.apple.fairplay'] 
 
}; 
 
var keySystemsCount = (function() { 
 
    var count = 0; 
 
    for (keysys in keySystems) { 
 
    if (keySystems.hasOwnProperty(keysys)) { 
 
     count += keySystems[keysys].length; 
 
    } 
 
    } 
 
    return count; 
 
})(); 
 

 
var testVideoElement = document.createElement('video'); 
 
var supportedSystems = []; 
 
var unsupportedSystems = []; 
 

 
var supportsEncryptedMediaExtension = function() { 
 
    if (!testVideoElement.mediaKeys) { 
 
    if (window.navigator.requestMediaKeySystemAccess) { 
 
     if (typeof window.navigator.requestMediaKeySystemAccess === 'function') { 
 
     console.log('found default EME'); 
 
     hasEME = true; 
 
     var isKeySystemSupported = function (keySystem) { 
 
      var config = [{initDataTypes: ['cenc']}]; 
 
      if (window.navigator.requestMediaKeySystemAccess) { 
 
      window.navigator.requestMediaKeySystemAccess(keySystem, config).then(function (keySystemAccess) { 
 
       supportedSystems.push(keySystem); 
 
      }).catch(function() { 
 
       unsupportedSystems.push(keySystem); 
 
      }); 
 
      } 
 
     }; 
 
     var keysys, dummy, i; 
 
     for (keysys in keySystems) { 
 
      if (keySystems.hasOwnProperty(keysys)) { 
 
      for (dummy in keySystems[keysys]) { 
 
       isKeySystemSupported(keySystems[keysys][dummy]); 
 
      } 
 
      } 
 
     } 
 
     } 
 
    } else if (window.MSMediaKeys) { 
 
     if (typeof window.MSMediaKeys === 'function') { 
 
     console.log('found MS-EME'); 
 
     hasEME = true; 
 
     var keysys, dummy, i; 
 
     for (keysys in keySystems) { 
 
      if (keySystems.hasOwnProperty(keysys)) { 
 
      for (dummy in keySystems[keysys]) { 
 
       if (MSMediaKeys.isTypeSupported(keySystems[keysys][dummy])) { 
 
       supportedSystems.push(keySystems[keysys][dummy]); 
 
       } else { 
 
       unsupportedSystems.push(keySystems[keysys][dummy]); 
 
       } 
 
      } 
 
      } 
 
     } 
 
     } 
 
    } else if (testVideoElement.webkitGenerateKeyRequest) { 
 
     if (typeof testVideoElement.webkitGenerateKeyRequest === 'function') { 
 
     console.log('found WebKit EME'); 
 
     hasEME = true; 
 
     var keysys, dummy, i; 
 
     for (keysys in keySystems) { 
 
      if (keySystems.hasOwnProperty(keysys)) { 
 
      for (dummy in keySystems[keysys]) { 
 
       if (testVideoElement.canPlayType('video/mp4', keySystems[keysys][dummy])) { 
 
       supportedSystems.push(keySystems[keysys][dummy]); 
 
       } else { 
 
       unsupportedSystems.push(keySystems[keysys][dummy]); 
 
       } 
 
      } 
 
      } 
 
     } 
 
     } 
 
    } else { 
 
     console.log('no supported EME implementation found'); 
 
     hasEME = false; 
 
    } 
 
    } 
 
}

semplicemente eseguire supportsEncryptedMediaExtension() e supportati I sistemi verranno riempiti con le informazioni desiderate.

+1

Questo è fantastico! Dove hai trovato l'elenco delle stringhe di sistema chiave? So che "org.w3.clearkey" deriva dalla specifica w3 - https://w3c.github.io/encrypted-media/#common-key-systems -. Ma ho difficoltà a rintracciare da dove provengono gli altri. – Boushley

+1

Sembra che Safari non venga definito nella proprietà 'webkitGenerateKeyRequest'. Qualcuno sta sperimentando questo problema? Grazie –

1

Oltre alle informazioni elencate qui, voglio menzionare che in Chrome, se si sta utilizzando https o non si influirà sulla disponibilità della funzione navigator.requestMediaKeySystemAccess.

Nel vostro ambiente di sviluppo che, probabilmente, è in esecuzione su http, navigator.requestMediaKeySystemAccess tornerà undefined per Chrome, mentre lo stesso codice restituirà una funzione in Firefox.

Nel vostro ambiente prod che ha https, navigator.requestMediaKeySystemAccess restituirà una funzione sia in Chrome e Firefox.

Problemi correlati