我想創建一個Google環聊應用,通過環聊按鈕(StartData)獲取YouTube視頻ID,然後與其他環聊參與者共享並觀看視頻。使用Google環聊API播放單個Youtube視頻並與其他參與者分享
工作流程:
1)點擊谷歌的視頻羣聊按鈕
2)YouTube視頻ID獲取與STARTDATA
3)獲取並保存在STARTDATA共享gapi.hangout.data國家,以便其他谷歌視頻羣聊參與者發送檢索相同的視頻。
4)添加youtube事件監聽器,以便在共享狀態下播放/暫停,以便其他參與者一起觀看YouTube視頻。
這裏是我的XML文件:
基本的谷歌的Hangouts應用
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0 *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License
-->
<ModulePrefs title="Fitcasts">
<Require feature="rpc" />
<Require feature="views" />
<Require feature="locked-domain" />
</ModulePrefs>
簡單的播放/暫停按鈕
<Content type="html"><![CDATA[
<script src="//talkgadget.google.com/hangouts/api/hangout.js?v=1.0"></script>
<style type="text/css">
</style>
<h2>Pause/Play Buttons for YouTube Videos</h2>
# play pause button for youtube
<a src="#" class="button" id="play-button">Play
</a>
<a src="#" class="button" id="pause-button">Pause
</a>
的iframe只是隨機視頻頂部起初我想讓它成爲一個特定的視頻一個 // STARTDATA與谷歌的視頻羣聊按鈕
<iframe id="video" src="//www.youtube.com/embed/FKWwdQu6_ok?enablejsapi=1&html5=1" frameborder="0" allowfullscreen></iframe>
它
<script>
// https://developers.google.com/youtube/iframe_api_reference
function HangoutDemo() {
console.log("Starting...");
gapi.hangout.onApiReady.add(this.onApiReady.bind(this));
}
HangoutDemo.prototype.onApiReady = function (event) {
if (event.isApiReady === true) {
console.log("API Ready");
document.getElementById("play-button").onclick =
this.buttonClick.bind(this);
gapi.hangout.data.onStateChanged.add(// add callback for event
this.buttonClick.bind(this)
);
this.buttonClick();
}
};
HangoutDemo.prototype.buttonClick = function() {
// global variable for the player
var player;
// this function gets called when API is ready to use
function onYouTubePlayerAPIReady() {
// create the global player from the specific iframe (#video)
player = new YT.Player('video', {
events: {
// call this function when player is ready to use
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
// bind events
var playButton = document.getElementById("play-button");
playButton.addEventListener("click", function() {
player.playVideo();
});
var pauseButton = document.getElementById("pause-button");
pauseButton.addEventListener("click", function() {
player.pauseVideo();
});
}
// Inject YouTube API script
var tag = document.createElement('script');
tag.src = "//www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
};
var hangoutDemo = new HangoutDemo();
</script>
]]>
</Content>
</Module>
這是一噸的代碼。把你的問題降低到發生錯誤的地步,而不是讓我們創建你的系統。 – nook