Dear Developers,
As I am working on a school project I gotten myself into a problem. I am developing an application in C# and WPF. The SWFObject (http://code.google.com/p/swfobject/) is implemented in a windows of my application (in a WebBrowser element).
The swf object is loaded into the WebBrowser Element using a custom page I have created:
<!-- saved from url=(0016)http://localhost -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
// This function is called when an error is thrown by the player
function onPlayerError(errorCode) {
alert("An error occured of type:" + errorCode);
}
// This function is called when the player changes state
function onPlayerStateChange(newState) {
updateHTML("playerState", newState);
}
// Pass the display information about the current state of the player to the application
function updatePlayerInfo() {
// Also check that at least one function exists since when IE unloads the
// page, it will destroy the SWF before clearing the interval.
if(ytplayer && ytplayer.getDuration) {
window.external.InvokeMeFromJavascript(ytplayer.getDuration(), ytplayer.getCurrentTime(), ytplayer.getVideoBytesTotal(), ytplayer.getVideoStartBytes(), ytplayer.getVideoBytesLoaded());
}
}
// This function is automatically called by the player once it loads (funtion: loadPlayer)
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("ytPlayer");
// This causes the updatePlayerInfo function to be called every 250ms to
// get fresh data from the player
setInterval(updatePlayerInfo, 250);
updatePlayerInfo();
ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
ytplayer.addEventListener("onError", "onPlayerError");
}
// This function is called by the application as soon as the webbrowser in the player window is done loading
function loadPlayer( videoIdDynamic ) {
// The video to load
var videoIdStatic = "QZ40WlshNwU"
// Lets Flash from another domain call JavaScript
var params = { allowScriptAccess: "always" };
// The element id of the Flash embed
var atts = { id: "ytPlayer" };
// All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
swfobject.embedSWF("http://www.youtube.com/e/" + videoIdDynamic + "?enablejsapi=1&version=3&playerapiid=ytplayer&autoplay=1&hd=1&controls=0&iv_load_policy=3",
"ytapiplayer", "100%", "100%", "8", null, null, params, atts);
}
// This function is called by the application when the player window exits before it was finished playing
function pauseVideo() {
ytplayer = document.getElementById("ytPlayer");
if (ytplayer) {
ytplayer.pauseVideo();
}
}
</script>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
overflow: auto;
padding: 0;
margin: 0;
}
</style>
</head>
<body style="width:100%; height:100%;">
<div style="width:100%;height:100%;">
<div id="ytapiplayer">Error ##: The embedded YouTube player could not load.</div>
</div>
</body>
</html>
As you can see the magic happens at the function updatePlayerInfo(). All player and video data is passed from this function to the WebBrowser element. The WebBrowser element passes this data through to the scripthelper. The script helper will update the data to UI elements in my WPF application (such as the time bar and download bar).
For every new video a new window will be opened, and after the current time of the video is equal to the duration, the application will close the window and trash the window object. Only one window can be active at a time.
Now the first 2 or 3 videos work perfect. But after that Javascript stops passing correct values and the only thing it passes are zero values. So this is my problem and I can't seem to solve it by myself because my knowledge about Action Script and Javascript are almost zero...
I would really be very glade full if some one can think with me on this problem!
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/WZF-vNSFm48J.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.
No comments:
Post a Comment