/** * 海外判定 * @return {bool} 関数定義済みか未定義かのエラーハンドリングで判定 */ function isOverSeaVideo() { try { //この関数が定義されていれば国内 checkIp(); return true; } catch (e) { return false; } } /** * ポップアップ表示 * @param {string} 表示するポップアップ * @param {string} パラメータ */ function popupVideo(popup, data) { var url = '/video/PopUpPc/' + popup; $.ajax({ url: url, type: 'POST', data: data, timeout: 5000, success: function (response) { $('#bgLayer').fadeIn(); $('#open-popup').fadeIn(); $('#open-popup').empty(); $('#open-popup').append(response); var winH = $(window).height(); var modalH = $('#open-popup').height(); var adjH = (winH - modalH) / 2; $('#open-popup').css("top", adjH); $(window).resize(); $('.ui-closeModal').click(function (e) { $('#bgLayer').fadeOut(); $('.mod-modal').fadeOut(); e.preventDefault(); }); } }); } /** * レンタル * @param {string} パックID * @param {int} 品質同意フラグ * @param {string} SPサイトのURL(不使用) */ function rentalVideo(packId, qualityConsentFlag, spUrl) { // GAログ if (typeof eventForceFire == "function") { eventForceFire(); } // 海外判定 if (!isOverSeaVideo()) { popupVideo('Oversea', { type: 'pack', id: packId }); return false; } // レンタルチェック(同期通信) var ret; $.ajax({ url: '/video/rentalcheck', type: 'POST', data: { packId: packId, qualityConsentFlag: qualityConsentFlag }, dataType: 'json', cache: false, async: false, timeout: 5000, success: function (data) { ret = data; }, error: function (xhr, status, error) { return false; } }); // エラーログ送信する場合 if (ret['SendErrorLog'] && typeof eventForceFire == "function") { eventForceFire(true); } // リダイレクトの場合 if (ret['Redirect'] != null) { location.href = ret['Redirect']; return false; } // ポップアップの場合 var popup = ret['Popup']; if (popup != null) { if (popup === 'MoveSpSite') { popupVideo(popup, { type: 'pack', id: packId }); } else if (popup === 'DeprecatedBrowserForRental') { popupVideo(popup, { url: ret['UrlFromPopup'] }); } else { popupVideo(popup); } return false; } return false; } /** * 再生 * @param {string} ストーリーID * @param {string} ストーリーID2 (字吹の場合にライブラリ側で2重視聴制御で使用) * @param {string} パックID * @param {bool} 予告編の場合はtrue * @param {bool} DRM必須フラグ * @param {bool} 無料の場合はtrue * @param {int} 1:第一世代エンコード, 2:第二世代エンコード * @param {int} 1:SD, 2:HD */ function playVideo(storyId, storyId2, packId, isTrailer, drmFlg, isFree, encodeGenFlag, qualityConsentFlag, ableToPlay) { // GAログ if (typeof eventForceFire == "function") { eventForceFire(); } // 海外判定 if (!isOverSeaVideo()) { popupVideo('Oversea', { type: 'story', id: storyId }); return false; } // 再生チェック(同期通信) var ret; $.ajax({ url: '/video/playcheck', type: 'POST', data: { storyId: storyId, isTrailer: isTrailer, drmFlg: drmFlg }, dataType: 'json', cache: false, async: false, timeout: 5000, success: function (data) { ret = data; }, error: function (xhr, status, error) { return false; } }); // エラーログ送信する場合 if (ret['SendErrorLog'] && typeof eventForceFire == "function") { eventForceFire(true); } // リダイレクトの場合 if (ret['Redirect'] != null) { location.href = ret['Redirect']; return false; } // ポップアップの場合 var popup = ret['Popup']; if (popup != null) { if (popup === 'MoveSpSite') { var data = { type: 'story', id: storyId }; if (typeof ableToPlay !== "undefined") { data = { type: 'story', id: storyId, play: ableToPlay }; } popupVideo(popup, data); } else { popupVideo(popup); } return false; } // IE判定 if (isIE()) { // 「今後このメッセージを表示しない」が設定されている場合は無視 if (getCookie("HIDE_IE_ALERT") == null) { popupVideo('IEAlert', { storyId: storyId, storyId2: storyId2, packId: packId, isTrailer: isTrailer, drmFlg: drmFlg, encodeGenFlag: encodeGenFlag, qualityConsentFlag: qualityConsentFlag }); return false; } } // 予告編でない場合は視聴履歴登録(非同期) if (!isTrailer) { $.ajax({ url: '/video/view_history/regist', type: 'POST', data: { storyId: storyId }, dataType: 'json', cache: false, async: true, timeout: 5000 }); } var viewPeriodResult = "0"; var redirectUrl = null; // 視聴期限設定(同期通信) $.ajax({ type: 'POST', url: '/video/view_period/regist', data: { fullStoryId: storyId, fullPackId: packId, isTrailer: isTrailer, isFree: isFree }, dataType: 'json', cache: false, async: false, timeout: 5000 }).done(function (data, textStatus, jqXHR) { viewPeriodResult = data.Result; redirectUrl = data.Redirect; if (viewPeriodResult !== "1") { playError('視聴期限設定エラー', JSON.stringify(data), jqXHR.status); } }).fail(function (jqXHR, textStatus, errorThrown) { playError('視聴期限設定エラー', jqXHR.responseText, jqXHR.status); }); // 未ログインの場合はログインに遷移 if (viewPeriodResult === "-1") { if (redirectUrl != null) { location.href = redirectUrl; return false; } } if (viewPeriodResult !== "1") { popupVideo('PlayerError'); return false; } var accessToken = null; $.ajax({ type: 'POST', url: '/video/vm_access_token/get', dataType: 'json', cache: true, async: false, timeout: 5000 }).done(function (data, textStatus, jqXHR) { accessToken = data.AccessToken; }).fail(function (jqXHR, textStatus, errorThrown) { playError('アクセストークン取得エラー'); }); if (accessToken == null) { popupVideo('PlayerError'); return false; } var playToken = null; var accountId = ''; var playerEnv = '2'; $.ajax({ type: 'POST', url: '/video/vm_play_token/get', data: { fullStoryId: storyId, fullPackId: packId, qualityConsentFlag: qualityConsentFlag }, dataType: 'json', cache: true, async: false, timeout: 5000 }).done(function (data, textStatus, jqXHR) { accountId = data.AccountId; playToken = data.PlayToken; playerEnv = data.PlayerEnv; }).fail(function (jqXHR, textStatus, errorThrown) { playError('再生トークン取得エラー'); }); if (playToken == null) { popupVideo('PlayerError'); return false; } if (storyId2 == null) { storyId2 = ''; } // プレイヤー再生 mdjPlayVideo(accountId, storyId, storyId2, encodeGenFlag, accessToken, playToken, qualityConsentFlag, playerEnv); return false; } // 再生 function mdjPlayVideo(accountId, fullStoryId, fullStoryId2, encodeGenFlag, accessToken, playToken, qualityConsentFlag, playerEnv) { var playerUrl = "/video/Content/pc-content/player/index.html?" + "userId=" + encodeURIComponent(accountId) + "&fullStoryId1=" + encodeURIComponent(fullStoryId) + "&fullStoryId2=" + encodeURIComponent(fullStoryId2) + "&encodeGen=" + encodeURIComponent(encodeGenFlag) + "&accessToken=" + encodeURIComponent(accessToken) + "&playToken=" + encodeURIComponent(playToken) + "&qualityConsentFlag=" + encodeURIComponent(qualityConsentFlag) + "&env=" + encodeURIComponent(playerEnv); callPlayer(playerUrl); } function callPlayer(playerUrl) { $(".playerBox").colorbox({ iframe: true, width: "80%", height: "80%", scrolling: true, returnFocus: false, overlayClose: false, closeButton: false, opacity:0.6, open:true, href:playerUrl }); } function isIE() { var ua = window.navigator.userAgent.toLowerCase(); return (ua.indexOf('msie') >= 0 || ua.indexOf('trident') >= 0); } $(function() { $(".playerBox").colorbox({ iframe: true, width:"100%", height:"100%", scrolling: true, returnFocus: false, overlayClose: false, closeButton: false, opacity:0.6 }); $(window).resize(function(){ $.colorbox.resize({width:'80%', height:'80%'}); }); }); function playError(errorMessage, responseData, status) { var message = errorMessage + '(status=' + status + ',response=' + responseData + ')'; $.ajax({ type: 'POST', url: '/video/ajax/logerror', data: { message: message }, dataType: 'json', cache: true, async: false, timeout: 5000 }); }