Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

JW Player and ASP.NET FLV Streaming

14 replies [Last post]

I have been searching the forums for a about a day now, I cannot find one clear post about how to successfully implementing streaming of an FLV file with the JW Player and ASP.NET, preferably C#. This link says to search the forums, but I have had no luck:
http://www.longtailvideo.com/support/tutorials/HTTP-Video-Streaming

- This article came up multiple times: http://blogs.ugidotnet.org/kfra/archive/2006/10/04/50003.aspx, but if you bring up the page in firefox and try to play the sample video on the page it never plays!
- The longtail tutuorial above has a PHP example using xmoov.php as the streaming file, has anyone ever created an xmoov.asp or aspx so I can just use that example? In the forums I just saw people arguing about whether to use s1.addVariable("streamscript" or s1.addVariable("file" and no one posted a full example. I also saw an example that used a ashx handler, couldnt get that to work either. I am a web developer so if I can't figure this out how are other people? Please help! Thank you.

This thread seems to end with a successful streamer on Nov. 17, 2008, once a few typOs were fixed.

I don't use that "stuff", so I can't comment on the code itself.

Currently, with a v4.6.247 player, your player code should be:

'streamer': 'http://www.domain.com/path/streamer.aspx',
'file': 'videofile.flv',

The streamer URI ABSOLUTELY MUST be a full URI, including the protocol and domain.

If your file URL (filename only in this case) doesn't end in a recognized media file extenstion (in this case, only flv can be pesudostreamed), then use a type of video.

And of course, the FLV file must have the metadata created and injected by FLVMDI, flvtool2, flvtool++, yamdi, or flvmeta.

So the javascript would look like:

s1.addVariable('streamer': 'http://www.domain.com/path/streamer.aspx');
s1.addVariable("file", "Videos/videofile.flv");

- The one thing I can't find is the code that is in streamer.aspx. I just searched 'streamer.aspx' and nothing came up in the forums.

streamer.aspx is a generic filename for your streaming script.

The only one that I know of is in the thread that I referenced above (NOT!).

Here's the thread:

    [http://www.longtailvideo.com/support/forum/Setup-Problems/6804/Using-a-Url-for-the-file-parameter#ms...

(Look at the code posted on Nov. 17, 2008 — Sorry about not posting the URI before.)

Here are some other threads:

    http://www.longtailvideo.com/support/forum/Modules/294/Anyone-have-an-ASP-playlist-generator-

    http://www.longtailvideo.com/support/forum/JavaScript-Interaction/11346/Use-of-an-asp-or-aspx-instea...

And this search:

    http://www.longtailvideo.com/jw/?search=asp+playlist+generator

Thanks, i will take a look.

Ugh, I've taken a look at every link I can find, this one you mentioned got me close I think:
http://www.longtailvideo.com/support/forum/Setup-Problems/6804/Using-a-Url-for-the-file-parameter#ms...

- Alright I am going to list everything I have here, it has to be close and maybe you can help / find something for me. See this link for reference:
http://www.fronseetest.com/autoid_video/Default.aspx
- Notice how it just says "Video Stream Not Found" and my video name, so it is at least trying.

- Version 4.2.95 of JW Player.

- Here is the main javascript part of the Default.aspx page above:
<script type='text/javascript' src="embed/swfobject.js"></script>

<div id='container'></div>
<script type='text/javascript'>
var s1 = new SWFObject('embed/player.swf', '_player', '614', '420', '9', '#ffffff');
s1.addParam('allowfullscreen', 'true');
s1.addParam('allowscriptaccess', 'always');
s1.addVariable('file', 'halo.flv');
//s1.addVariable('image', '');
s1.addVariable('autostart', 'true');
s1.addVariable('stretching', 'uniform');
s1.addVariable('streamer', 'http://localhost:4516/VideoWeb/Stream.asp');
s1.write('container');
</script>

- Here is Stream.asp:
<%@ Language=VBScript %>
<%
Response.Buffer = true
Response.ContentType = "video/x-flv"

'I've tried it with and without these lines, still the same:
'Dim FileSize, ByteCounter
'FileSize = CreateObject("scripting.filesystemobject").GetFile(valFile).Size
'Response.AddHeader "Content-Length", FileSize

'request position and file name
Dim valPos,valFile
valPos = Request("start")
valFile = Server.Mappath(Request("file"))

'check whether file type is FLV
If (LCase(Right(valFile,Len(valFile)-InstrRev(valFile,"."))) <> "flv")Then
Response.End
End if

'if position was not passed set pos to 0
If (valPos = "") Then
valPos = 0
End if

'create streaming object
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile(valFile)

'if pos is greate than 0 proceed to get FLV header information
If (valPos > 0) Then
Response.BinaryWrite objStream.Read(13)
End if

'set position to begin streaming
objStream.Position = valPos

'loop through file, flush and clear buffer each time
do while Not objStream.EOS
Response.BinaryWrite objStream.Read (163840)
Response.Flush
Response.Clear
loop

'close stream object
objStream.Close
Set objStream = Nothing
%>

- Some in that article mentioned that their Headers were off, I wasnt sure which page to
check, Default.aspx? Would I use a tool like this: http://www.seoconsultants.com/tools/headers.asp
- and what am I looking for / changine?

- I've listed every possibly thing I can! Please help! How is there not a step by step article for this yet? Maybe this thread could be it? Thank you Lost

Joe

I actually got some help elsewhere (through direct contact with support) and you cannot use "localhost" in the streamer URL, so if you check my fronseetest URL above it does play.
BUT, my only other issue is that the seeking functionality doesnt work. Try clicking ahead and the screen just goes blank? Do I have to handle that event somehow? I thought this line would handle it in Streamer.asp:

'if pos is greate than 0 proceed to get FLV header information
If (valPos > 0) Then
Response.BinaryWrite objStream.Read(13)
End if

- Are my headers in the page off then?

Thank you!!!!

Joe

This conversation with my self is great. I fixed the seeking issue by just using the latest version of the player (player.swf) 4.5.218 as of today. So if anyone else is looking for an ASP.NET streaming solution everything you need is above!!

v4.6.248 is the latest and it has some important bug fixes.

http://developer.longtailvideo.com/trac/log/trunk/as3/player.swf?rev=249

Click on the @249 in the Rev column to download it.

Glad to hear that you got the streaming working. Could you post your final aspx file for others to use? Thanks.

Oh, sorry I never came back to this page, here is the Javascript I use on my page that plays the video, for some reason the page HAD TO be in the same directory as my videos I was streaming:

<script type='text/javascript' src="../embed/swfobject.js"></script>
<div id='container'></div>
<script type='text/javascript'>

var s1 = new SWFObject('../embed/player.swf', '_player', '594', '400', '9', '#ffffff');
s1.addParam('allowfullscreen', 'true');
s1.addParam('allowscriptaccess', 'always');
s1.addVariable('file', requestedVideoName);

s1.addVariable('autostart', 'true');
s1.addVariable('stretching', 'uniform');
s1.addVariable('streamer', 'http://174.37.165.11/Stream.asp');

s1.write('container');

</script>

requestedVideoName above is just a javascript variable with the name of the video.

And here is the full Stream.asp file:

<%@ Language=VBScript %>
<%
Response.Buffer = true
Response.ContentType = "video/x-flv"

Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1

' do not allow proxy servers to cache this page !! to be used on all pages
Response.CacheControl = "private"
Response.CacheControl = "no-cache"

'request position and file name
Dim valPos,valFile,vidURL
vidURL = "Videos/"
valPos = Request("start")
valFile = Server.Mappath(vidURL + Request("file"))

'check whether file type is FLV
If (LCase(Right(valFile,Len(valFile)-InstrRev(valFile,"."))) <> "flv")Then
Response.End
End if

'if position was not passed set pos to 0
If (valPos = "") Then
valPos = 0
End if

'create streaming object
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile(valFile)

'if pos is greate than 0 proceed to get FLV header information
If (valPos > 0) Then
Response.BinaryWrite objStream.Read(13)
End if

'set position to begin streaming
objStream.Position = valPos

'loop through file, flush and clear buffer each time
do while Not objStream.EOS
Response.BinaryWrite objStream.Read (163840)
Response.Flush
Response.Clear
loop

'close stream object
objStream.Close
Set objStream = Nothing
%>

 
@Joe,

Thank you very much for the script. I'll save a copy for future requests.

but a C# copy where can I find?
does anybody have one, for this script?

Joe, your solution doesn't work for me... :(

Check out Code Shop:
http://h264.code-shop.com/trac

hello sir,

my problem is, how can i play the video direct in flv player,when my videos are there in grid view.when i click the link it is not playing in flv player,it is first get downloaded and than ask me to open with.i need it to play directly in flv player as soon as i click on any video in grid view.my player code is in html and grid view is in aspx page.

please help me

thanking you

geetika

@geetika - Can you provide a link to where you are running this?