Recently I had the need to play videos , stored in my database, in ApEx. Although this seemed like a difficult task, it’s pretty easy to accomplish.
What I needed was an embedded video player (like Windows Media Player) to play the video on my ApEx page in a specific region.
1. Create a new ApEx page with an empty html region
2. Now let’s create some html code so we can display the windows Media Player in your web browser. Paste the next code in your html region source:
< object id=”MediaPlayer” width=320 height=286 classid=”CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95″ standby=”Loading Windows Media Player components…” type=”application/x-oleobject” codebase=”http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112″>
<param name=”filename” value=””>
<param name=”Showcontrols” value=”True”>
<param name=”autoStart” value=”True”>
<embed type=”application/x-mplayer2″ src=”” name=”MediaPlayer” width=320 height=240></embed>
The parameter filename will need the location where our file is stored, since the videos are stored in the database we will need to create a function that would return the video.
The parameter Showcontrols will show us player controls like ‘Play, Pause and Stop’ when set to ‘True’.
The parameter autoStart will start the video automatically when set to ‘True’.
You might notice the embed type, this is needed to play your video in Mozilla family browsers, The object tag is used for IE.
Run your page and you will see an empty Media Player:
3. Now create a procedure that will download your file to your web browser.
This is procedure could look like this:
PROCEDURE download_file(p_file_id IN files.file_id%TYPE)
CURSOR c_my_file IS
FROM files cmp
WHERE file_id = p_file_id;
FETCH c_my_file INTO rec_my_file;
IF c_my_file%FOUND THEN
htp.p(‘Content-length: ‘ || rec_my_file.file_length);
htp.p(‘Content-Disposition: attachement; filename=”‘||rec_my_file.file_name||’”‘);
4. Grant your procedure an execute to public otherwise APEX_PUBLIC_USER will not be able to execute it later on.
5. Now that we have our procedure we can implement it into our media player, open the source of your html region:
Change the next things:
<param name=”filename” value=”#OWNER#.pck$files.download_file?p_file_id=41″>
<embed type=”application/x-mplayer2″ src=”#OWNER#.pck$files.download_file?p_file_id=21″ name=”MediaPlayer” width=320 height=240></embed>
Although I use 21 hard coded for demo purposes here, you could always use an item of course. Note that my procedure is located in the package pck$files.
6. Run you page and you will see a nice movie playing in your ApEx webpage.
If you are planning to use this then I suggest you write a procedure that would display the apex code for the windows media player also, this way it’s more maintainable.