-
MediaPlayer
인스턴스를 만듭니다.
player = new MediaPlayer();
-
MediaPlayerCapabilityChangeEvent.HAS_DRM_CHANGE
이벤트를 플레이어에 등록합니다. 내용이 DRM으로 보호된 경우 이 이벤트가 전달됩니다.
player.addEventListener(MediaPlayerCapabilityChangeEvent.HAS_DRM_CHANGE, onDRMCapabilityChange);
-
이벤트 핸들러에서
DRMTrait
인스턴스를 얻습니다.
DRMTrait
는
authenticate()
같은 DRM 관련 메서드를 호출하는 데 사용되는 인터페이스입니다. DRM 보호 내용을 로드할 경우 OSMF는 DRM 유효성 검사 작업을 수행하고 상태 이벤트를 전달합니다.
DRMEvent.DRM_STATE_CHANGE
이벤트 핸들러를
DRMTrait
에 추가합니다.
private function onDRMCapabilityChange
(event :MediaPlayerCapabilityChangeEvent) :void
{
if (event.type == MediaPlayerCapabilityChangeEvent.HAS_DRM_CHANGE
&& event.enabled)
{
drmTrait = player.media.getTrait(MediaTraitType.DRM) as DRMTrait;
drmTrait.addEventListener
(DRMEvent.DRM_STATE_CHANGE, onDRMStateChange);
}
}
-
onDRMStateChange()
메서드에서 DRM 이벤트를 처리합니다.
private function onDRMStateChange(event :DRMEvent) :void
{
trace ( "DRMState: ",event.drmState);
switch(event.drmState)
{
case DRMState.AUTHENTICATION_NEEDED:
// Identity-based content
var authPopup :AuthWindow = AuthWindow.create(_parentWin);
authPopup.serverURL = event.serverURL;
authPopup.addEventListener("dismiss", function () :void {
trace ("Authentication dismissed");
if(_drmTrait != null)
{
//Ignore authentication. Just
//try to acquire a license.
_drmTrait.authenticate(null, null);
}
});
authPopup.addEventListener("authenticate",
function (event :AuthWindowEvent) :void {
if(_drmTrait != null)
{
_drmTrait.authenticate(event.username, event.password);
}
});
authPopup.show();
break;
case DRMState.AUTHENTICATING:
//Display any authentication message.
trace("Authenticating...");
break;
case DRMState.AUTHENTICATION_COMPLETE:
// Start to retrieve voucher and playback.
// You can display the voucher information at this point.
if(event.token)
// You just received the authentication token.
{
trace("Authentication success. Token: \n", event.token);
}
else
// You have got the voucher.
{
trace("DRM License:");
trace("Playback window period: ",
!isNaN(event.period) ? event.period == 0 ?
"<unlimited>" : event.period : "<none>");
trace("Playback window end date: ",
event.endDate != null ? event.endDate : "<none>");
trace("Playback window start date: ",
event.startDate != null ? event.startDate : "<none>");
}
break;
case DRMState.AUTHENTICATION_ERROR:
trace ("DRM Error:", event.mediaError.errorID +
"[" + DRMErrorEventRef.getDRMErrorMnemonic
(event.mediaError.errorID) + "]");
//Stop everything.
player.media = null;
break;
case DRMState.DRM_SYSTEM_UPDATING:
Logger.log("Downloading DRM module...");
break;
case DRMState.UNINITIALIZED:
break;
}
}
|
|
|