<video> tag, multiple options from the video directory

hello, if i use this code for playing videos on my site:

<video width="320" height="240" autoplay>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

Open in new window


how can i add an option where by i can choose which video to play? so maybe a drop down list or some sort of file tree which displays all video file names so i can choose which one to watch?

thanks
zac
LVL 1
bede123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
easiest way but hardest to  maintain is simply create a bunch of the video tags
<video width="320" height="240" autoplay>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video><video width="320" height="240" autoplay>
  <source src="movie1.mp4" type="video/mp4">
  <source src="movie1.ogg" type="video/ogg">
Your browser does not support the video tag.
</video><video width="320" height="240" autoplay>
  <source src="movie2.mp4" type="video/mp4">
  <source src="movie2.ogg" type="video/ogg">
Your browser does not support the video tag.
</video><video width="320" height="240" autoplay>
  <source src="movie3.mp4" type="video/mp4">
  <source src="movie3.ogg" type="video/ogg">
Your browser does not support the video tag.
</video><video width="320" height="240" autoplay>
  <source src="movie4.mp4" type="video/mp4">
  <source src="movie4.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

Open in new window


There are several players i.e. jwplayer that support lists
0
Leonidas DosasCommented:
HTML:
<div style="text-align:center"> 
  <button onclick="playPause()">Play/Pause</button> 
  <button onclick="nextButton()">Next</button>
  <br> 
  <video id="video1" width="420">
    <source src="C:/sample.mp4" type="video/mp4">
    <source  type="video/mp3">
    <source type="video/ogg">
    Your browser does not support HTML5 video.
  </video>
</div> 

Open in new window


Javascript script:
var myVideo=document.getElementById("video1"); 
var videoList=['part_1.mp4','part_2.mp4','part_3.mp4','part_A.mp3','movie_bbb.ogg'];
var index = videoList.indexOf(window.currentVideoName);
//Next button
function nextButton(){
myVideo.pause();
myVideo.currentTime=0;
index = index + 1;
if(index==videoList.length)
index = 0;
alert(videoList[index]);
myVideo.src = 'C:/'+videoList[index];
window.currentVideoName=videoList[index];
myVideo.play();
}
function playPause()
{ 
if (myVideo.paused) 
  myVideo.play(); 
else 
  myVideo.pause(); 
} 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bede123Author Commented:
ok thanks guys. problem is if i upload new vids to my directory then i have to edit the code each time?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

David Johnson, CD, MVPOwnerCommented:
Correct it is not dynamic but static
0
Leonidas DosasCommented:
If you upload new video files then add them into the videoList array via push method.
0
bede123Author Commented:
thank you, can you show me the push method please.

so would my html page look like this?

<html>

<head>
<title> page 1</title>
</head>

<body>
<h1>hello world</h1>
<p>this is the text</p>

var myVideo=document.getElementById("video1"); 
var videoList=['part_1.mp4','part_2.mp4','part_3.mp4','part_A.mp3','movie_bbb.ogg'];
var index = videoList.indexOf(window.currentVideoName);
//Next button
function nextButton(){
myVideo.pause();
myVideo.currentTime=0;
index = index + 1;
if(index==videoList.length)
index = 0;
alert(videoList[index]);
myVideo.src = 'C:/'+videoList[index];
window.currentVideoName=videoList[index];
myVideo.play();
}
function playPause()


<div style="text-align:center"> 
  <button onclick="playPause()">Play/Pause</button> 
  <button onclick="nextButton()">Next</button>
  <br> 
  <video id="video1" width="420">
    <source src="C:/sample.mp4" type="video/mp4">
    <source  type="video/mp3">
    <source type="video/ogg">
    Your browser does not support HTML5 video.
  </video>
</div> 

</body>

</html>

Open in new window

0
Leonidas DosasCommented:
In this case you must use php code to get the filenames from the  server directory. Specially you can use readdir() php function to get all the filenames. Or alternative when you click to select the file to upload ie:
<input type="file" id="txtfiletoread" />

Open in new window

you can get and set the filename to the array via this js code:
var elm=document.getElementById('txtfiletoread');
elm.addEventListener('change',function(){  
  var a=this.value.split('\\'); 
  a=a[a.length - 1];
  videoList.push(a);
});

Open in new window

0
bede123Author Commented:
ok thanks guys. this quetion is evolving into something else. i will now close this question based on the answers given but then i will ask another question with php tagged.

thanks again
zac
0
bede123Author Commented:
thank you for your help. i will put together a file and then ask another question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.