﻿// CallWebServiceMethods.js


function GetIndir2(obj)
{

    if((obj.newstate == 'PLAYING') && (seekFlag))
    {
        //player.sendEvent('PLAY'); // trigger pause
        seekFlag = false;
        //seek=Samples.AspNet.WebService.GetCurrentFileTime(OnGetSeekTime);
        setTimeout("player.sendEvent('SEEK', seek)",  100);
    }
    else {
    if(obj.newstate == 'PAUSED'){
        player.sendEvent('PLAY', true);
    }
    }    
//    else  
//        if((obj.newstate == 'PLAYING') && !(seekFlag))
//        {
//            seekFlag = true;
//            seek=Samples.AspNet.WebService.GetCurrentFileTime(OnGetSeekTime);
//            //setTimeout("player.sendEvent('SEEK', seek)",  100);
//        };
    
   if(obj.newstate == 'COMPLETED')
   {
     //seek=Samples.AspNet.WebService.GetCurrentFileTime(OnGetSeekTime);
     Samples.AspNet.WebService.GetCurrentFile(OnGetIndirComplete);
   };

   currentState = obj.newstate;     
    
}

function GetIndirMyPlayList(obj)
{

   if(obj.newstate == 'COMPLETED')
   {
     Samples.AspNet.WebService.GetNextMyPlayListFile(MyPlayListUserId,MyPlayListItem,OnGetNextMyPlayListFileComplete);
   };

   currentState = obj.newstate;     
    
}

function OnGetNextMyPlayListFileComplete(result, userContext, methodName)
{
//alert("Result: " + result + "\n" + "Context: " + userContext + "\n" + "Method name: " + methodName);
    

    url=result;
    //alert(url);
	MyPlayListItem+=1;

	var obj = {file:  result };
    player.sendEvent("LOAD", obj);
	
    //player.sendEvent("LOAD",{file:' +result });
    player.sendEvent('PLAY',true);
    
    
}

function GetRndTN(obj)
{
        currentState = obj.newstate;
        if(currentState == 'COMPLETED')
        {
          Samples.AspNet.WebService.GetRndFileTN(OnGetIndirComplete);
        }
    
}

function OnGetIndirComplete(result, userContext, methodName)
{
//alert("Result: " + result + "\n" + "Context: " + userContext + "\n" + "Method name: " + methodName);
    

    url=result;
    //alert(url);
	
	var obj = {file:  result };
    player.sendEvent("LOAD", obj);
	
    //player.sendEvent("LOAD",{file:' +result });
    player.sendEvent('PLAY',true);
    
    
}

function OnGetSeekTime(result, userContext, methodName)
{
//alert("Result: " + result + "\n" + "Context: " + userContext + "\n" + "Method name: " + methodName);
    

    url=result;
    //alert(url);
	
	var obj = {file:  result };
    player.sendEvent("SEEK", obj);
    //player.sendEvent('PLAY',true);
    seekFlag = true;
}
            
            
// This function calls the Web service method without 
// passing the callback function. 
function GetNoReturn()
{
    Samples.AspNet.WebService.GetServerTime();
    alert("This method does not return a value.");
    
}


// This function calls the Web service method and 
// passes the event callback function.  
function GetTime()
{
    Samples.AspNet.WebService.GetServerTime(
    SucceededCallback);
    
}


// This function calls the Web service method 
// passing simple type parameters and the 
// callback function  
function Add(a,  b)
{
    Samples.AspNet.WebService.Add(a, b, 
    SucceededCallback);
}

// This function calls the Web service method 
// that returns an XmlDocument type.  
function GetXmlDocument() 
{
    Samples.AspNet.WebService.GetXmlDocument(
        SucceededCallbackWithContext, FailedCallback,
        "XmlDocument")
}

// This function calls a Web service method that uses
// GET to make the Web request.
function MakeGetRequest() 
{

    Samples.AspNet.WebService.EchoStringAndDate(
        new Date("1/1/2007"), " Happy",
        SucceededCallback, 
        FailedCallback, "HappyNewYear");

}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName)
{
    var output;
    
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    
    var readResult;
    if (userContext == "XmlDocument")
	{
	
	    if (document.all) 
	        readResult = 
		        result.documentElement.firstChild.text;
		else
		    // Firefox
		   readResult =
		        result.documentElement.firstChild.textContent;
		
	     RsltElem.innerHTML = "XmlDocument content: " + readResult;
	}
    
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs)
{
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    RsltElem.innerHTML = result;
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
    // Display the error.    
    var RsltElem = 
        document.getElementById("ResultId");
    RsltElem.innerHTML = 
    "Service Error: " + error.get_message();
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
