开发者

How to pass cookie to AxShockwaveFlash from C#?

I'm developing a video player using WPF and AxShockwaveFlash.

It has following steps:

  1. find video from a web service.
  2. it acquires information of each video.
  3. pass vid开发者_开发百科eo information to AxShockwaveFlash and embedded flash video player.
  4. embedded flash video player starts streaming download from web service.

I have a problem on step 4.

Step 1-3 shares a cookie (CookieContainer), but step 4 can not.

How can I pass its cookie to embedded flash video player?


Its little longer trick, instead of using Shockwave, you should use the WebBrowser and navigate to an ashx or aspx page with all cookies set from your cookiecontainer to webbrowser's cookies.

In order to set cookie correctly you must create a page on your asp.net website as "RedirectWithSession.ashx",

public class RedirectWithSession : IHttpHandler{

      public void ProcessRequest(HttpContext context){
           Response.Cookies.Add("ASP.NET_SessionID", Request.QueryString["SessionID"]);
           Response.Redirect(Request.QueryString["RedirectUrl"]);
      }

}

Now in your WPF app, you must find out ASP.NET_SessionID cookie and pass it on the url to webbrowser as,

http://host.com/RedirectWithSession.ashx?SessionID=[SessionID]&RedirectUrl=[Url]

Your webbrowser will first visit the handler, it will then set session correctly and then your video url will be loaded, this way your session of your webservice context and webbrowser context will be shared.

I just showed you example of ASP.NET_SessionID , you can pass multiple cookies. This is the best way to do it, you can also use custom page and javascript etc, but i dont know if they will work correctly in all security modes.


you can pass "flashvars" to the Flash Active X object, for example

<object type="application/x-shockwave-flash" 
data="myFlashThingy.swf" width="100%" height="100%">

<param name="play" value="true" />
<param name="movie" value="myFlashThingy.swf" />
<param name="menu" value="false" />
<param name="quality" value="high" />

<param name="flashvars" value="videoURL='http://somewhere.com/video.flv'" />

And then you can access those "flashvars" in the ActionScript code.

In ActionScript2 you'd do it like this :

var videoURL:String = _root.videoURL;

And in ActionScript3 you'd do it like this :

var flashVars:Object = (this.root.loaderInfo as LoaderInfo).parameters;
var videoURL:String = flashVars.videoURL;

Hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜