Play video from url?
BlitzMax Forums/BlitzMax Programming/Play video from url?
| ||
how do I play video from url? |
| ||
Greatly depends on what kind of video, and what dependencies the player has. If is it a directly hosted video file, or some web-based streaming media platform? HTML5? Flash? Some custom 3rd part plugin? Open, or DRM encumbered? (In all likelihood, the answer is "you won't.") |
| ||
A video hosted on my website. I want to play a video file like from http::mywebsite.com/videos/video1.mp4 |
| ||
You can download the MP4 file from withing Blitzmax fairly easily. Here's a sample that downloads the google logo from their server as an image into blitzmax and then display it on the screen:Graphics 400, 300, 0 DrawText "Getting Image...", 140, 144 Flip Local img:TImage = LoadImage(LoadBank("http::www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png")) If Not img Then RuntimeError "Unable to download image" 'Graphics img.width, img.height, 0 Graphics 1024,768 DrawImage img, 0, 0 Flip WaitKey() End A difficulty with MP4 is that Blitzmax doesn't have built-in ability to display that video format, meaning you'll need a 3rd party decoder to actually DO anything with the video after downloading it. I don't know of any MP4 decoders for blitzmax myself, although there's definitely MPG and Ogg vorbis decoders for blitzmax around. (If you have control over the file you want to play, you can always convert it to an Ogg Vorbis video and upload that to your website instead) |
| ||
so how do I play ogg video from url? |
| ||
Try using a 3rd party mod, like Brucey's bah.oggvorbis, and call it using the loadbank("http:: syntax. (You may be able to do it without the loadbank statement as well, but whether or not that works depends on the file format you're trying to load -- some file loaders need to seek around in the stream which won't work unless it has everything loaded into a bank first) |
| ||
Before you dive wholehearted into this one thing that would annoy ANY gamer is having a game, a crap Internet connection and it loads everything from the net. Pirates wouldn't bother they would download ya files and hack the loader code, it's the legitimate users ya would be hurting. |
| ||
Here is one method, tested on an IE11 Windows machine.Import MaxGui.Drivers Strict Local window:TGadget Local htmlview:TGadget 'window=CreateWindow("My Window",30,20,600,440) 'fullscreen window=CreateWindow("My Window",0,0,DesktopWidth(),DesktopHeight(),Null,0) htmlview=CreateHTMLView(0,0,ClientWidth(window),ClientHeight(window),window) SetGadgetLayout htmlview,1,1,1,1 HtmlViewGo htmlview,"file://"+RealPath("movie.html") While WaitEvent() Print CurrentEvent.ToString() Select EventID() Case EVENT_GADGETDONE Print "GADGETDONE" Local src$="http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" Local script$="document.getElementById(~qvidsource~q).src=~q"+src+"~q" HtmlViewRun htmlview,script Case EVENT_WINDOWCLOSE End End Select Wend and in same folder the file movie.html <!DOCTYPE html> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> </head> <body> <video width=100% height=100% controls=controls> <source id=vidsource type="video/mp4"> Media Not support. </video> </body> </html> [edit] modified to set movie src from BlitzMax |
| ||
I don't want to use html I want to do it from url in blitzmax. http::mywebsite.com/videos/videointro.ogg also I want to play video and sound. |
| ||
Fair enough. I have modified the code to set src from BlitzMax and would be interested in solving the sound issue even if you don't use it. The idea is it is a function that plays a movie, if it needs a handle to the Graphics window / screen you are using to behave correctly then we could look at sorting that out also. Streaming a movie and decompressing it seamlessly is big call for a BlitzMax solution. If you are Windows only you also have the option of using one of BlitzMax's older siblings for the job, both BlitzPlus and Blitz3D can handle the process of showing a movie seamlessly using still supported Direct Show API and you could call such a movie player app from your BlitzMax code... |
| ||
show me code in blitzmax how to load movie file from url. |
| ||
HtmlViewRun htmlview,script |
| ||
show me code in blitzmax how to load movie file from url. A "please" is nice too, sometimes... |
| ||
I know but nobody is telling me how to do it without html there should be a way to load it in blitzmax. I want to load ogg video from url in blitzmax not html. please? |
| ||
I know but nobody is telling me how to do it without html there should be a way to load it in blitzmax And there probably is -- see the starting point above, and good luck figuring it out. |
| ||
I had a go at streaming theoraplayer over http:: but since http:: doesn't support seeking, it didn't work very well. Under NG, the theoraplayer TStream functionality turns out to work very well on seekable media (like from the filesystem). Technical notes : Because of the nature of the GC NG uses, you don't need to enable threading to get this to run - although even with threading enabled on legacy BlitzMax, it had big stability issues with the threaded callbacks. So yeah, not much success there. As a workaround, I would envisage a stream wrapper which can cache the fetched data in order to support some kind of pseudo seeking functionality. Of course, if the library wants to seek to the end of the file, you've just gone and downloaded the whole thing anyway, in which case you may as well download it and play it locally. |
| ||
@ Caton - what exactly is wrong with html? Did you even try the code I posted? If I wrap it in a Function End Function block then would you look at it? |
| ||
becuase It loads from a data list file and it's needs to play video files from a list config data. html can't do that I'm using blitzmax so I can play videos from url and files from url. I have aready read files from url just need video to play from url |
| ||
It'll be a 2 step process... 1. libcurl from Brucey will stream the file from just the url address, and as Brucey already points out - using this method to get to the end of stream will download the whole file first. 2. what you do with that stream data of course is up to you - in your case you'll want to pass the stream into an appropriate video decoder and render the video/audio. Both of which are not native to BlitzMax and as Brucey has done step 1 already it'll be up to you, or someone else to resolve step 2. edit: An alternative better approach would be to setup rtsp on the server and serve the file over that protocol, which is designed for that exact purpose. Again something that you'd have to do yourself as BMax doesn't handle that natively. |
| ||
Downloading the file when changed would be much more appreciated by your end users than downloading every time you start the game. |
| ||
Got video playing with LibVLC! Surprisingly easy once you get a handle on how VLC does things... IMPORTANT: Read notes at link below before trying to use. This is a very simple, limited example and only renders into a given window -- no idea about rendering into textures/images, etc, but perhaps someone else will be interested enough to explore further. Use VLC DLL to play video Example in thread shows minor mod to stream the Big Buck video from URL posted above. Allow through firewall and try again if it fails! If it doesn't work, you probably didn't read the notes... |
| ||
Thats pretty cool :-) well done!! |
| ||
Ha ha, thanks! |