Click here to Skip to main content
15,894,343 members
Articles / Web Development / ASP.NET

Silverlight YouTube Jukebox

Rate me:
Please Sign up or sign in to vote.
4.97/5 (72 votes)
27 Apr 2010CPOL12 min read 221.4K   3.2K   119  
Search and play YouTube videos inside a Silverlight 4.0 application! Learn about RIA Services, right-click event handling, themes, and styles.
  • mediastore.zip
    • MediaStore
      • _ReSharper.MediaStore
        • BuildScriptCache
          • .crc
          • .version
          • 0
          • 5
            • 36ffebe3.dat
        • DecompilerCache
        • ModuleIds.xml
        • NamedArguments
          • .crc
          • .version
          • 2
            • 68a91b39.dat
        • PdbInfo
          • b44f4be46623b83c18bcb9c7ef0ccf674da302c6
          • fa721ee25d1bd163495d202eeada5552c2f334cc
        • ProjectModel
          • ProjectModel.dat
        • Resources
          • .crc
          • .version
          • 0
          • 1
            • 1c34c2be.dat
        • SymbolCache.bin
        • TagPrefixes
          • .crc
          • .version
          • 0
          • 9
            • 4f91e12f.dat
        • TodoCache
          • .crc
          • .version
          • 5
          • 7
            • 4348e689.dat
        • WebsiteFileReferences
          • .crc
          • .version
        • WordIndex
          • .crc
          • .version
          • 1
            • 55d27f8f.dat
          • 3
          • 5
          • 8
          • 9
            • 7616753.dat
      • MediaStore.5.0.ReSharper.user
      • MediaStore.5.1.ReSharper.user
      • MediaStore.sln
      • MediaStore.suo
      • MediaStore.Web
      • MediaStore
        • App.xaml
        • App.xaml.cs
        • Assets
        • Bin
          • Debug
            • ActivityControl.dll
            • AppManifest.xaml
            • ar
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • bg
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • ca
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • cs
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • da
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • de
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • Divelements.SilverlightTools.dll
            • el
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • es
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • et
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • eu
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • fi
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • fr
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • he
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • hr
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • hu
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • id
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • it
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • ja
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • ko
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • lt
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • lv
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • MediaStore.dll
            • MediaStore.pdb
            • MediaStore.xap
            • ms
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • nl
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • no
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • pl
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • pt
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • pt-BR
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • ro
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • ru
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • sk
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • sl
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • sr-Cyrl-CS
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • sr-Latn-CS
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • sv
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • System.ComponentModel.DataAnnotations.dll
            • System.ComponentModel.DataAnnotations.xml
            • System.ServiceModel.DomainServices.Client.dll
            • System.ServiceModel.DomainServices.Client.Web.dll
            • System.ServiceModel.DomainServices.Client.Web.xml
            • System.ServiceModel.DomainServices.Client.xml
            • System.ServiceModel.Web.Extensions.dll
            • System.ServiceModel.Web.Extensions.xml
            • System.Windows.Controls.Data.DataForm.Toolkit.dll
            • System.Windows.Controls.Data.Input.dll
            • System.Windows.Controls.Data.Input.xml
            • System.Windows.Controls.dll
            • System.Windows.Controls.DomainServices.dll
            • System.Windows.Controls.DomainServices.xml
            • System.Windows.Controls.Navigation.dll
            • System.Windows.Controls.Navigation.xml
            • System.Windows.Controls.Theming.ExpressionDark.dll
            • System.Windows.Controls.Theming.ExpressionDark.pdb
            • System.Windows.Controls.Theming.Toolkit.dll
            • System.Windows.Controls.Theming.Toolkit.pdb
            • System.Windows.Controls.Theming.Toolkit.xml
            • System.Windows.Controls.xml
            • System.Windows.Data.dll
            • System.Windows.Data.xml
            • TestPage.html
            • th
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • tr
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • uk
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • vi
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.resources.dll
            • zh-Hans
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
            • zh-Hant
              • System.ComponentModel.DataAnnotations.resources.dll
              • System.ServiceModel.Web.Extensions.resources.dll
              • System.Windows.Controls.Data.Input.resources.dll
              • System.Windows.Controls.Navigation.resources.dll
              • System.Windows.Controls.resources.dll
              • System.Windows.Data.resources.dll
        • Controls
        • Generated_Code
        • GlobalSuppressions.cs
        • Helpers
        • Libs
          • ActivityControl.dll
          • Divelements.SilverlightTools.dll
          • System.Windows.Controls.Data.DataForm.Toolkit.dll
        • MainPage.xaml
        • MainPage.xaml.cs
        • MediaStore.csproj
        • MediaStore.csproj.user
        • Models
        • Properties
        • TrackContextMenu.xaml.cs
        • Views
        • Web
          • Resources
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MediaStore.Web.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
	<!-- ajax search api and video search control code -->
	<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=internal-solution"
	    type="text/javascript"></script>
	<script src="http://www.google.com/uds/solutions/videosearch/gsvideosearch.js"
	    type="text/javascript"></script>

	<!-- ajax search stylesheet, video search stylesheet -->
	<link href="http://www.google.com/uds/css/gsearch.css" rel="stylesheet"
	    type="text/css"/>
	<link href="http://www.google.com/uds/solutions/videosearch/gsvideosearch.css"
	    rel="stylesheet" type="text/css"/>
      
    <title>MediaStore</title>
    <style type="text/css">
	    html, body {
		    height: 100%;
		   overflow: auto;
		   background-color:#161616;
		   
	    }
	    body {
		    padding: 0;
		    margin: 0;
	    }
	    #silverlightControlHost {
		    height: 100%;  
		    text-align:center;
	    }
	    
	    
	   /*Set styling attributes on the videosearch element*/
	    #videosearch {
		    width : 350px; 
			margin:auto;
			font-family: Arial;
			font-size:0.6em;
			color:White;
		}
		p {
			font-family: Arial;
			font-size:0.8em;
			padding-left:10px;
			color:White;
		}
		

		/* Set player width and height
		 * keep a 1.33 ratio
		 * (on widths > 300px, add 20px in height for controls)
		 * small player:        180x135   4:3
		 * medium player:       260x195   4:3
		 * large player:        320x260   4:3 + 20px at bottom
		 * extra large player:  480x380   4:3 + 20px at bottom
		 */
		.playerBox_gsvsc .player_gsvsc {
	  		width : 320px;
	  		height : 260px;
		}
		/*hide search form*/
		.searchForm_gsvsc 
		{
			
			visibility:hidden;
		}
		/*hide footer*/
	    .footerBox_gsvsc 	{
			
			 display : none;
		}
			
		/* image border color */
		.results_gsvsc div.video-result_gsvsc 
		{
			border-color : #000000; 
			
		}

		/* small image border color */
		.tiny-results_gsvsc  div.tiny-video-result_gsvsc 
		{
			border-color : #000000; 
			
		}

		/* primary colors */
		.app_gsvsc {                                                    color : #ffffff; }
		.search-form-complete_gsvsc div.search-form-save_gsvsc {        color : #ffffff; }
		div.search-form-save_gsvsc {                                    color : #ffffff; }
		div.edit-tag_gsvsc {                                            color : #ffffff; }
		.footerBox_gsvsc a {                                            color : #ffffff; }
		.playerBox_gsvsc a.title_gsvsc {                                color : #ffffff; }
		div.more_gsvsc:hover {                                          color : #ffffff; }
		div.more_gsvsc:visited {                                        color : #ffffff; }
		div.more_gsvsc:link {                                         	color : #ffffff; }

		/* selected tag */
		div.tag-selected_gsvsc {                                        color : #ffffff; }

		/* hover colors */
		div.tag-control_gsvsc:hover {                                   color : #ffffff; }

    </style>
	<script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
    	function onSilverlightError(sender, args) {
    		var appSource = "";
    		if (sender != null && sender != 0) {
    			appSource = sender.getHost().Source;
    		}

    		var errorType = args.ErrorType;
    		var iErrorCode = args.ErrorCode;

    		if (errorType == "ImageError" || errorType == "MediaError") {
    			return;
    		}

    		var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

    		errMsg += "Code: " + iErrorCode + "    \n";
    		errMsg += "Category: " + errorType + "       \n";
    		errMsg += "Message: " + args.ErrorMessage + "     \n";

    		if (errorType == "ParserError") {
    			errMsg += "File: " + args.xamlFile + "     \n";
    			errMsg += "Line: " + args.lineNumber + "     \n";
    			errMsg += "Position: " + args.charPosition + "     \n";
    		}
    		else if (errorType == "RuntimeError") {
    			if (args.lineNumber != 0) {
    				errMsg += "Line: " + args.lineNumber + "     \n";
    				errMsg += "Position: " + args.charPosition + "     \n";
    			}
    			errMsg += "MethodName: " + args.methodName + "     \n";
    		}

    		throw new Error(errMsg);
    	}


    	/**
    	* Google AJAX VideoSearch Control 
    	*/	
    	
    	var options = {  string_allDone: "Close Video" };//customize "all done" string
		var videoSearchControl;

		/**
		* Create a new GSvideoSearchControl.
		*/
		function CreateVideoSearchControl() {
    		// establish default search tags
	    		var defaultTags = [
	        { query: "" },
	        { query: "" },
	        { query: "" },
	        { query: "" }
	      ];

	    		videoSearchControl = new GSvideoSearchControl(
	        document.getElementById("videosearch"),         // container
	        defaultTags,                                // default tag array
	        null,
	        null,
	        options		 //customizable options tag 
	        );
    	}

    	/**
    	* Initiate a new search by calling the videosearch control.
    	*/
    	function SearchForClip(searchString) {
    		CreateVideoSearchControl();
		    videoSearchControl.execute(searchString);
		}

	</script>
</head>
<body>
	<form id="form1" runat="server" style="height:100%">
		<div id="silverlightControlHost">
		    <object id="xaml" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
				<param name="source" value="ClientBin/MediaStore.xap"/>
				<param name="onError" value="onSilverlightError" />
				<param name="background" value="white" />
				<param name="minRuntimeVersion" value="3.0.40624.0" />
				<%
				string currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
				Response.Cookies.Add(new HttpCookie("MediaStore-culture", currentCulture));
				%>
				<param name="uiculture" value="<%= System.Threading.Thread.CurrentThread.CurrentCulture %>" />
				<param name="windowless" value="true" /> <!--Set windowless mode-->
				<param name="autoUpgrade" value="true" />
				<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
					<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
				</a>			
				</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
		</div>
	</form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager Outcoder
United States United States
Katka has several years of experience working in software development in the areas of market research and e-commerce. She has wide ranging experience in developing Java, ASP.Net MVC, ASP.Net, WPF, Silverlight, and Windows Phone applications.

Company: Outcoder.com
Group: XAML Experts
Proud co-creator of: Surfy browser, Airlock Browser

Comments and Discussions