PHP& MySQL Video Playlist (JW Player)

I have been tweaking this a bit. Take a look at the admin panel so far:
http://maranatha.web44.net/DB_Videos//administrar/videoAdmin.php

I need to add certain behavior to the form. When you go to the page choose the Video 1, and then click on on the first Box: Video Name . You will notice that the value of this box disappear.

I added and onClick event to the input box: [php][/php] which clears the value of the text box on click.

I need this behavior only to happen when we choose Add New Video from the dropdown select box to clear the initials values. We don’t want to clear the values of existing fields… that will be done is the users chooses to edit the field values.

I fixed the delete issue and now it works just fine. However, there’s still one more issue with the form. When edit the Video Name, it actually inserts a new row of data… that is a new video in the DB. So update is actually inserting,NOT updating.

If you make an edit to description and Author only, without touch the video Name, the the update takes place just fine.

One more thing, and this is not an issue, rather a functionality add-on. There should be messages like “Video 23 Has been Successfully Deleted/Updated” so the user gets a feedback that the changes were actually made.

Had a minute before bed…

You have to override the Onclick, MouseUp options. The default for a textbox is EMPTY the text on selecting the box. You have to block these out. I found a lot online, but, this blog shows one way to do it. Look down a post or two for the GREEN CHECK showing the solved code… There is a lot of other notes where they were trying things a little like our back-and-forth posts… Some were interesting about this topic, but, not worth reading if you can get the GREEN CHECK one to work…

http://stackoverflow.com/questions/97459/automatically-select-all-text-on-focus-in-winforms-textbox

I have done this in the past, but the way we passed the values form thejavasript to the fields is what makes it tricky. In the past, for instance I had something like this:

[php][/php]

You see the value here comes from a PHP variable, so is so much easier to manage.

So I need something that says , i.e, If value== “Add New Video”, Then clear text box.

The thing is that we are using a single box for many different values. IN the sample above, for instance, the onclick events works fine because it’s password box where only the password is displayed.

I read the blog and I think they are talking about something different. I want to replace a calue with new on (nothing in this case). will figure that out tomorrow.

OK, fixed the issue. I found this nice tutorial about Clearing Default Text at http://www.yourhtmlsource.com/forms/clearingdefaulttext.html

As you can see now: http://maranatha.web44.net/DB_Videos/administrar/videoAdmin.php, the input text boxes’ content is replaced/cleared dynamically only as needed. Existing database fields will not be replaced on click, just when the user actually edits the content.

I was able to customized the script to our needs by just editing one line of code:
[php]function clearDefaultText(e) {
var target = window.event ? window.event.srcElement : e ? e.target : null;
if (!target) return;

//Modified by JJ-DR to SPECIFY Target existing value to clear and replace form values
if (target.value == 'enter VIDEO DESCRIPTION here' || target.value == 'enter new VIDEO NAME here' || target.value == 'enter AUTHOR name here' 
   || target.value == 'Type Name for your Video' || target.value == 'Type Name for your Video' || target.value == 'type a name for your video'|| 
   target.value == 'type a description for your video' | target.value == "type authors' name here") {
    target.value = '';
}

}[/php]

This is great, but now one issue arrived:
I think the Add New Video! part should be in its own category or tab instead of being part of the same dropdown list where the videos load, as it is setup currently.

The reason for this is that, as you know, the Add New Video! is a very important part of the whole project. What currently happens is that Add New Video! loads at the bottom of the playlist. Right now is not too bad because the playlist is short, but when it grows it will keep pushing Add New Video! down.

So say that the list grows to something like 50 videos, Add New Video! will be very further down on the dropdown list, and the user might not even see it at all, or will have to scroll a lot to get to it…

Two possible solutions that come to my mind are:
1) Move Add New Video to the very top of the list, and make sure it stays there.

2 And this one brings special attention as well. I am not sure if you’re already thinking/planning this, but will the videos be loaded by Albums (Playlist)? This behavior would be similar to the actual video page, just that the videos would load in another list intead of the JW Player.

Imagine that the dropdown list is a list of the albums (or playlists in the DB). So say that the albums you have so far are: ALBUM 1, ALBUM 2, ALBUM 3. You click on ALBUM 1, and list of the videos for ALBUM 1 appears either in another dropdown to select, or in some sort of scrollable list. So when the user (admin user) comes to the page, he/she first select an ALBUM/playlist to edit, then edit the individual videos for that particular ALBUM, and NOT the entire list of videos collection in the database.

This latter implementation will reduce clutter, and will help ease on a potential issue YOU brought before, in terms of the amount of items a dropdown list can hold without crashing. I must say that most of the ALBUMS/playlists that will be created are fairly small: 10-20 videos. However, some will be very large. For instance – and this is for your consideration, the church currently hosts over 400 hymns that church goers know by either name or number (i,e., Hymn #37 Praise the lord). I know that This is particular ALBUM people will want to see in the website. Of course the church doesn’t currently have all the hymns in their database, but the idea that we add them as we get a grip of them.

Huh, just got another idea. I guess instead of having an ALBUM named Hymns = 400+ videos, we can split it like this: Hymns 1-50, Hymns, 51-100, etc. Also, since not every one knows the hymns by number, I think it would be useful to add a search box to player so they can match song by name or number (in the case of hymns).

I know this was a mouth full, but it’s better to bring the issues to the forefront rather than complicating things later. What do you think?

I’m back! LOL, lots to cover. First, yes, I was assuming once the Video uploads were complete and working, next we would have to handle the albums. And, finally would have to go back and do some paging or “pagination” code to parse thru long lists. One idea that I thought about was an alpha-list at the top to let people use ‘A-B-C’ to locate videos. Another idea is to list so many at at time as you mentioned. If we do the alpha format, it would be very easy to add, just have to add a query to pull whatever they select as a letter and dynamically change the list below… And, glad you figured out the not-erasing of fields. I can use that myself! Oh, yes, adding the ADD-NEW-VIDEO would need to be at both the top and bottom to save scrolling time. But, if you have 400 videos, divided up by 26 letters, sounds like that would be the way to go…

Now, onto the UPLOAD routines as we left off last week. I found a very nice pop-up CONTACT-FORM that you might be interested in… It does a very nice form that pops up nicely. It calls a simple routine and a lot of validation code behind the scenes. Here is the link:
http://www.html-form-guide.com/contact-form/simple-modal-popup-contact-form.html
I did not use this code, but, you might want to combine that code with my code below. Or, just add some CSS to mine to make it more “pretty”… Anyway, my code was originally for a client who needed to upload thumbnails of pictures. So, it mentions pictures not videos, but, it will upload any file. I store my videos and pictures in my “Images” folder under my root folder. This code also has info on the picture and details and some various code for checking file size (width and height). You may not need this, but, it is handy for thumbnails. Since you need a thumbnail this might be handy.
So, this is broken into three files. The first is just the calling HTML file. It is simple and you will understand it. Note the window’s size is set in the call. This can be set up however you wish. The second file is the actual pop-up which is can be any type of form you want. In this case it is just a simple browse form to submit a file to upload. It in turn, calls the PHP code which does some minor displays of the data. It check the thumbnail for a certain size and if it is okay it uploads it. You will have to delete that code to send a picture of other sizes. As is, it will upload a video since by default videos do not include size in their default properties. Here is the code to test:

Upload_Popup.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload Pix test!</title>
</head>
<body>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
	popupWindow = window.open(
		url,'popUpWindow','height=500,width=500,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<a href="JavaScript:newPopup('UploadPix.html');">Open a popup window that allows uploading a picture...</a>

</body>
</html>

UploadPix.html (simple form page)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>Upload a picture...</head>
<body>
  <form action="Upload_Picture.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <h1>&nbsp; </h1>
    <h1 align="center">Press &quot;Browse&quot; to locate the picture,<br />then, Submit to update it:<br /></h1>
    <div align="center">
      <input name="ufile" type="file" id="ufile" size="50" />
    </div>
    <p>&nbsp;</p>
    <div align="center">
      <input type="submit" name="UploadPixName" value="UPLOAD Your Picture" />
    </div>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
  </form>
</body>
</html>

Upload_Picture.php (Does the actual upload of the video/thumbnail)
[php]

<?php // Get correct file name to upload

$file_name = $_FILES[“ufile”];
$target_path = “Images/” . $file_name;

$picture = $_FILES[‘ufile’][‘tmp_name’];
list($width, $height, $type, $attr) = getimagesize($picture);

echo “”;

if ($_FILES[“ufile”][“error”] > 0)
{
echo "Return Code: " . $_FILES[“ufile”][“error”] . “
”;
}
else
if ($width == 192 && $height == 121)
{
echo "Upload Filename: " . $_FILES[“ufile”][“name”] . “
”;
echo “This Image is " . $width . " wide by " . $height . " tall.
”;
echo "Type: " . $_FILES[“ufile”][“type”] . “
”;
echo “Size: " . ($_FILES[“ufile”][“size”] / 1024) . " Kb

”;

    copy($_FILES["ufile"]["tmp_name"], $target_path);
    echo "Stored in: " . $target_path . "  AS  " . $file_name;
    }
else
   {
    echo "Upload Filename: " . $_FILES["ufile"]["name"] . "<br />";
    echo "This Image is " . $width . " wide by " . $height . " tall.<br>"; 
    echo "Type: " . $_FILES["ufile"]["type"] . "<br />";
    echo "Size: " . ($_FILES["ufile"]["size"] / 1024) . " Kb<br /><br>";

    echo "********************************************<br>";
    echo "***  This thumbnail file is not 192x121! ***<br>";
    echo "***  THe file was not copied, please set ***<br>";
    echo "***  up a new thumbnail from original.   ***<br>";
    echo "***  Then, update the picture again.     ***<br>";
    echo "********************************************<br>";
   }

echo “


”;
echo “Press here to return to ADMIN…”;
echo “

”;
echo “Press here to return to upload another picture…”;
?>

[/php]

For testing, just create these three files and place on the server. Change the path if you need to wherever you want to store the files. Then, call the first html file and see what it does. (Afterwards, go back to the pop-up contact-us link and see how theirs look.) I think you can figure out the needed changes. Have fun…

Hey Ernie… I’m glad you are back. I was getting a bit nervous thinking you were eaten by a giant barracuda LOL.

I gust got home after a long day of running around. I will plug in tomorrow morning and will let you know how it all goes.

I want thing I would like to test right way is connecting the dropdown list with the player in the main page. I tried and failed miserably :slight_smile: http://maranatha.web44.net/DB_Videos/videos.php
Once again, thanks for helping along… I really appreciate it… you’ve been godsend to me.

Here’s the code so far: [php]

VIDEO DB body { background-color: #666; } <?php //include('administrar/connect_maranatha_000webhost.php'); include('../_includes/functions.php'); ?>
<?php echo ''.getVideos().''?>
        <div id="videoFrame">
        	<div id="video_TOP"></div>
            <div id="video_MIDDLE">            	
          	  <div id="container">Loading the player...</div>
              <script type="text/javascript" src="mediaplayer_5-9/jwplayer.js"></script>
			<script type="text/javascript">
                    jwplayer("container").setup({
                        flashplayer: "mediaplayer_5-9/player.swf",
                        'frontcolor': '000000',
                        'lightcolor': 'D0A72B',
                        'screencolor': 'd4cfcf',
                        'autostart': 'true',
                        'controlbar': 'bottom',
                        'repeat': 'always',
                        'volume': '75',
                        'shuffle': 'true',
                        'autoHide': "always",		
                        'playlist.position': "bottom",		
                        
                        'height': 550,
                        'width': 598,
                        'stretching': 'uniform',
                        //stretching options: uniform,fill,exactfit,bestfit,none		
                        
                        'skin':'mediaplayer_5-9/skins/beelden/beelden.zip',
                        //avilable skins:beelden, bekle, five, minima, modieus,skins, stijl
                        <?php
                        $query = mysql_query('SELECT * FROM video_albums');			
                        while ($row = mysql_fetch_array($query)){
                        $albumPlaylist = $row['playlist']; //get data
                        //$albumName = $row['albumName']; //get data		
                        print $albumPlaylist;                             
                        }			
                         ?>                            
                    });
                </script>
              </div>
            
            <div id="screen_bottom"></div>
            </div>
[/php]

And again, here’s the function I use to generate the dropdownlist. I put it in functions file to keep the main page a bit clean:
getVideos() function
[php]function getVideos(){
$query = mysql_query(“SELECT * FROM video_albums”) or die(mysql_error());

//start and first row of the table Highlight here
echo "<font class='text'>ALBUMS".'</font>'."<select name='videos'>";

if(mysql_num_rows($query)==0){
	echo'<tr class="tableHL-header"> <td colspan="\4\">NO POSTS ALBUMS FOUND!</td></tr>';
	} else	{
		
	//HIGHLIGHT TABLE ROWS *******************************
    //$i is set as One (1).  for Highlighting table rows.
	$i=1;
	while($albums = mysql_fetch_assoc($query)){
		
	//$i goes up with every iteration, this finds the remainder of $i divide by 2, therefore all odd numbers will return '1' and all even numbers '0'
	$x=$i %2;
	
	//if statement sets odd numbers as white and even numbers as grey
	if($x == 1) {
	$class = "dropdown_1";
	} else {
	$class = "dropdown_2";
	}
	//HIGHLIGHT TABLE ROWS ENDS*******************************
	//making the 'class' attribute a variable means that now all odd rows should be one color and all even rows another
	echo "<option class='$class'>".$albums['albumName']."</option>";
	$i++; //HIGHLIGHT TABLE ROWS CODE*************************
	}

}

}
?>[/php]

Talk to you tomorrow.

Well, a quick look at the PHP code shows that it is missing the ONCHANGE call in the
( ALBUMS".’’.""; ) That is the part that calls your javascript to reload the playlist into the player…

This is the part that I haven’t started looking at yet. I thought the next part was video and picture upload which I sent code for. Then, creation of the playlists from the video lists. And, lastly the changing of the playlist on the fly…

Anyway, I have been helping some others and working on a website to be tested tomorrow for a quilting/sewing shop. (No where done on it, LOL) SO, I should be programming for a few hours…
Let me know what you need next… I love this project…

LOL, that’s the thing a rookie programmer like me needs to cope with… balancing priorities is a hard thing to do when you are excited about another part of the project.

I am on the upload stuff right now and I will update on the status as I move along.

The project is definitively taking a life of its own… I love it!

ALL PROGRAMMING PROJECTS ARE JUST GREAT BIG “PUZZLES”!!!

And, who doesn’t like a good puzzle? LOL, I hear ya on the working on all the parts.
One idea snaps you over to another and then you forget where you are. The UPLOAD section is simple.
You will piece that together quickly.

One thing back on the playlist parts. Once you get your layout complete on ONE (1) playlist, one that fits the way you want ALL of your playlist to be set up as, post it for me and I will start on the creation code for creating the list from the video lists. Basically this is just like the previous work, one dropdown, one scrollable list and a little patch up code. So, post one of your latest playlists and I will tear it apart and get ready for when you are done with the upload parts…

Do you mean after I am done with the upload stuff?

Nevermind, I will take what I need from your sample you sent to me the other day…

Let me know when your upload stuff is done or if you have any questions about it.

I will keep you posted.

One quick update… Our project was broken up into these sections. I just wanted your to realize how far we have come along… (This is programmingly-speaking, not cosmetic-looks, that’s all yours, LOL!)

  1. the Player, which is done for right now…
    (Nearly done, works, allows selecting playlists, just have to link the playlists dynamically.)

  2. the Video Admin part , which is done for right now except the uploads…
    (Nearly done, works, allows updates to database, just have to allow for uploads.)

  3. the Playlist Admin part, which we haven’t started yet.
    (The layout will be identical to #2 with the addition of a scrollable list of video that were selected, easy)


Sooo, looking very good so far!

Hi Ernie.

I am taking a look at this file uploader: http://blueimp.github.com/jQuery-File-Upload/ It’s quite fancy and adds some pizazz to the project.

I found I was looking for a way to add a progress bar to the upload.

What do you think?

VERY “Pretty”! Yes, I would use it… It adds more fancy code. I was just sending you general code so you could do it yourself. It looks like a lot of options. I do not have time to play with it’s code or source. But, you can do that.

PS: I will not be home much tonight, have plans…

OK… I will implement as much as I can.

Some thoughts on the playlist ADMIN section. I foresee this as extremely easy.

First, copy your VideoAdmin page and rename it as PlaylistAdmin.
Change the page so it does not allow changes to the Video list.
Add a second list like the current Video items, but for Playlist’s.
On the side, add a scrollable list. (This will show the playlist’s videos by name only)
Once a video is selected on the left drop-down, it is added in the right list.
When a playlist is selected in the middle drop-down, the playlist info is displayed as the video ones are now.
If add-new playlist is selected, you can enter new info and the right-video list is cleared.
Somewhere there will be a CREATE-THIS-PLAYLIST button which can be press once all of the video have been added. If the user wants to alter a current playlist, they select it and then will be able to click on a video and move it up or down or delete it. That is easy to do with buttons that are enabled and disabled.

So, after getting the video upload in place, take a look at this list and make a plan. I have been looking at the playlist and it is very easy to create. Here is a quick breakdown…

First, a playlist is just text. It is basically, just going to be put together by parsing down the video list inside the scrollable list and when the CREATE-PLAYLIST button is push, you can take the video list in order and create the playlist text. And, then it is saved in the database with the info that was entered.

Playlist breakdown:
playlist: [
{ Video info (from database) },
{ repeated for each video }
],

Video info pulled from database: (repeated for each video in playlist)
{file: “VIDEOS/filename.flv”, image: “THUMBS/filename.jpg”, title: “text data”, description: “text data” },

So, to create a playlist from a list of video, you would follow something like this:
1 - Loop thru the list of video that the user selected (after making sure all the info fields are in place)
2 - Query the database and acquire all of the video data for current one
3 - Put this data into a playlist format:
$playlistvideo=’{file: “’ . $row[‘videolocation’] . '”, image: "’ . $row[‘videothumb’]… ETC…
4 - Add this playlistvideo to the playlist
5 - with all of the videos converted to a playlist format, write it to the database with the playlist info.
(Since this is just a text string, it will be a fast process and easy to manipulate.)

SO, that is the basics on creating a playlist from our video list. Sometime in the new future, I will have you zip up all of your code and post it in a private message so I can see it all together. No graphics or videos needed just the code so I can be on the same page as you. Just the player page, video admin and playlist admin pages. Also, for others that read this thread we should post a final product for other to access…

:smiley: :smiley: :smiley: ;D :smiley: ;D

GREAT… you are really fast LOL!

LOL, it’s easy to think… It’s hard to find that one comma or quote your forgot… Heee!

I was actually trying to give you enough to do as I have to do some of my own work now and get to the bank. I will be back in a couple hours and am not here tonight. So, make some headway and then let me know what you are stuck on… Later…

Trust me I got enough on my end. A lot of this stuff doesn’t come as easy to me. ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service