環境はXcodeを使用し、TVJS、TVMLにてTVOS向けのアプリケーションを作成しております。
アプリケーションの内容としては・・・
とある動画配信サイトをクロールして必要な情報をjson形式で引っ張り、そのjsonデータを加工してUIを表示、
表示されたサムネイル画像をクリックすると動画再生が始まる、といったものです。
jsonデータを加工してサムネイル画像を表示させるUIまではできたのですが、画像をクリックしても動画の再生が始まらない状態です。
画像クリック時にXcodeコンソールには以下のエラー内容が表示されています。
Xcode
1<IKAppContext (0): 0x6000001726c0> Error: undefined is not an object - undefined - line:0:0 22018-07-30 20:02:51.617542+0900 hoge_test[67395:1331136] [System] <Error>: <IKAppContext (0): 0x60400016d380> Error: undefined is not an object - undefined - line:0:0 32018-07-30 20:02:52.285882+0900 hoge_test[67395:1331239] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert 42018-07-30 20:02:52.286338+0900 hoge_test[67395:1331239] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert 52018-07-30 20:02:52.287397+0900 hoge_test[67395:1331239] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert 62018-07-30 20:02:52.288403+0900 hoge_test[67395:1331239] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert 72018-07-30 20:06:06.839613+0900 hoge_test[67395:1331034] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/hogehoge/Library/Developer/CoreSimulator/Devices/2C78A403-93E7-4A7C-B942-5FEDF86007DA/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 82018-07-30 20:06:06.841245+0900 hoge_test[67395:1331034] [MC] Reading from private effective user settings. 9
アプリケーション起動時に動作するjavascript(TVJS)のコードは以下になります。
javascript
1var baseURL; 2 3function getDocument(url){ 4 var templateXHR = new XMLHttpRequest(); 5 var url = url; 6 7 templateXHR.responseType = "document"; 8 templateXHR.addEventListener("load", function() {parseJson(templateXHR.responseText);}, false); 9 templateXHR.open("GET", url, true); 10 templateXHR.send(); 11} 12 13function parseJson(information){ 14 var result = JSON.parse(information); 15 var movies =""; 16 var length = Object.keys(result).length; 17 for(i = 0; i < Object.keys(result).length; i++) { 18 movies += '<lockup onselect="access(' + result[i].URL + ')"><img src="' + result[i].thumnail + '" width="246" height="138" /><title>' + result[i].title + '</title></lockup>'; 19 } 20 var template = '<document><stackTemplate><banner><title>TopMenu</title></banner><collectionList><shelf><section>' + movies + '</section></shelf></collectionList></stackTemplate></document>'; 21 var templateParser = new DOMParser(); 22 var parsedTemplate = templateParser.parseFromString(template, "application/xml"); 23 navigationDocument.pushDocument(parsedTemplate); 24} 25 26String.prototype.before = function(word, include){ 27 var idx = this.indexOf(word) 28 var l = include ? word.length : 0 29 return idx >= 0 ? 30 this.substr(0, idx + l) : 31 "" 32} 33String.prototype.after = function(word, include){ 34 var idx = this.indexOf(word) 35 var l = include ? 0 : word.length 36 return idx >= 0 ? 37 this.substr(idx + l) : 38 "" 39} 40 41function access(URL){ 42 $(function() { 43 $.ajax({ 44 type: 'GET', 45 url: URL, 46 timeout : 1000, 47 dataType: 'html', 48 success: function(data) { 49 //console.log($(data).find('#sample').text()); 50 $(data).find('div[class="vjs-poster"]').each(function(){ 51 var mediaURL = $style; 52 var mediaURL = str_replace('background-image: url("https://cf-images.ap-northeast-1.prod.boltdns.net/v1/jit/', '', mediaURL); 53 var val = mediaURL.before("/main/") 54 console.log(val); 55 }); 56 } 57 }); 58 var playURL = "https://manifest.prod.boltdns.net/manifest/v1/hls/v5/aes128/" + val + "/10s/master.m3u8?fastly_token=NWI4MGYwMjlfY2ZiODczZDU5YzVkNDA4MzA3YjI5Yzc2MWIyOWI3YmQwMWJmMzZiOTZhYjIyY2Q4NDBmOTk2Nzk4OWRlOGM0Mg%3D%3D"; 59 playMedia(playURL); // https://manifest.prod.boltdns.net/manifest/v1/hls/v5/aes128/ val /10s/master.m3u8?fastly_token=NWI4MGYwMjlfY2ZiODczZDU5YzVkNDA4MzA3YjI5Yzc2MWIyOWI3YmQwMWJmMzZiOTZhYjIyY2Q4NDBmOTk2Nzk4OWRlOGM0Mg%3D%3D 60 }); 61} 62 63function playMedia(URL) { 64 var videourl = URL; 65 var singleVideo = new MediaItem('video', videourl); 66 var videoList = new Playlist(); 67 videoList.push(singleVideo) 68 var myPlayer = new Player(); 69 myPlayer.playlist = videoList; 70 myPlayer.play(); 71} 72 73 74App.onLaunch = function(options) { 75 baseURL = options.BASEURL; 76 var jsonURL = baseURL + "json.json"; 77 console.log(jsonURL); 78 getDocument(jsonURL); 79} 80 81 82App.onExit = function() { 83 console.log('App finished'); 84} 85
上記コードのxmlテンプレートを作成するfor文にてfunction_accessを呼び出しているのですが、
どうもその呼び出しがうまくいっていないようです。
lockupタグのonselect以降を削除すると(UIにて画像をクリックしても何もそれ以上は起きませんが、)エラーは出力されません。
TVML、TVJSの記載についてはAppleDeveloper向けの資料を参考に記述を行いました。
リンク内容
記述に誤りがありそのご指摘、または他の方法をご提案頂いても構いません。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。