0
- 我以前在我的iOS應用中使用HTML字符串來播放youtube,如下所示。
我用來加載HTML作爲用WebView加載YouTube不起作用
[webView loadHTMLString:fileContents baseURL:[[NSBundle mainBundle] resourceURL]];
突然它已停止工作。它唯一的工作方式是如果我將baseURL設置爲像「http://www.example.com」這樣的http URL。我想知道什麼是正確的baseURL設置。
<div id='container'> <div id="child"> <div id="player"></div> </div> </div> <script> var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubeIframeAPIReady() { player = new YT.Player('player', { width: '%@', height: '%@', videoId: '%@', playerVars: { origin: 'file://', showinfo: 0, controls: 0, playsinline: 1, autoplay: 1 }, events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange, 'onPlaybackQualityChange': onPlayerPlaybackQualityChange, 'onPlaybackRateChange': onPlayerPlaybackRateChange, 'onError': onPlayerError, 'onApiChange': onPlayerApiChange } }); } // Event functions function onPlayerReady(event) { onEvent('ready', null); } function onPlayerStateChange(event) { onEvent('stateChange', playerStateToString(event.data)); } function onPlayerPlaybackQualityChange(event) { onEvent('playbackQuality', event.data); } function onPlayerPlaybackRateChange(event) { onEvent('playbackRateChange', event.data); } function onPlayerError(event) { onEvent('error', event.data); } function onPlayerApiChange(event) { onEvent('apiChange', event.data); } function onEvent(eventName, eventData) { var url = "ytplayer://event/" + eventName; if (eventData != null) { url += ('/' + eventData); } document.location = url; } // Helpers function playerStateToString(playerState) { var result = null; switch (playerState) { case -1: result = "unstarted"; break; case YT.PlayerState.ENDED: result = "ended"; break; case YT.PlayerState.PLAYING: result = "playing"; break; case YT.PlayerState.PAUSED: result = "paused"; break; case YT.PlayerState.BUFFERING: result = "buffering"; break; case YT.PlayerState.CUED: result = "cued"; break; } return result; } </script>
「
感謝您的回覆我用[一個NSBundle mainBundle] resourceURL]在真實的設備上它會翻譯成類似/ var/Applications/App%20Name的內容。你知道這是不是被允許的嗎? – user1191140