Jump to content

video tag


etsted

Recommended Posts

it doesnt work, when i specify the type attribute? why?

do i even need it?

 

it looks something like this:

 

<video width="320" height="240" controls> <source src="<?php echo $file_url;?>" type="video/mp4"> <source src=<?php echo $file_url;?>" > Your browser does not support the video tag. </video>

 

$file_url = "videos/2014042727116180637260000009088958.mp4";

Edited by etsted
Link to comment
Share on other sites

Well how was i supposed to know that! if you bothered to give us the original code, I would not have come to the conclusion that is was the misplacement of variable in question. You use different video formats (ogg, mp4, webm), for browsers that support these specific formats , as shown here http://www.w3schools.com/html/html5_video.asp IF you bothered even to look.

Link to comment
Share on other sites

// this is how i get the files from the DB

$mp4 = ""; // get all the mp3 files from the DB $sql = "SELECT * FROM mp3"; $query = mysqli_query($con, $sql); while($row = mysqli_fetch_array($query) ) { $id = $row['id']; $tittel = $row['tittel']; $description = $row['description']; $username = $row['username']; $file_url = $row['file_url']; $upload_date = $row['upload_date']; $mp4 .= "<video width='320' height='240' controls>n"; $mp4 .= "<source src='$file_url' type='audio/mpeg'>n"; $mp4 .= "</video>n"; }

 

// the url from the DB look like this

videos/2014042727116180637260000009088958.mp4

 

// this is how the echo part look like

 

<div><?php echo $show;?></div>

Link to comment
Share on other sites

The type is optional but it helps the browser choose the correct format more quickly, instead of loading each format until it can find one it can play.

 

if you have different audio and video types, you would have to distinguish what file format audio or video, them the correct audio/video tag and then source type to go with that specific format.

       $video_type = array();        $video_type['.mp4'] = 'video/mpeg';        $video_type['.ogg'] = 'video/ogg';        $video_type['.webm'] = 'video/webm';        $audio_type = array();        $audio_type['.mp3'] = 'audio/mpeg';        $audio_type['.ogg'] = 'audio/ogg';        $audio_type['.wav'] = 'audio/wav';        $concatenate_media = "";        $file_url = 'videos/2014042727116180637260000009088958.mp4';        //$file_url = 'http://www.w3schools.com/tags/horse.ogg';        $file_format = substr($file_url, -4); //get extension ('.mp4') and use as index for media type        if (substr($file_url, 0, 6) == "videos") {//check if in videos folder if not! it is treated as audio            $concatenate_media.= '<video width="320" height="240" controls>' . "n";            $concatenate_media.= '<source src="' . $file_url . '" type="' . $video_type[$file_format] . '">' . "n";            $concatenate_media.= '</video>' . "n";        } else {            $concatenate_media.= '<audio controls>' . "n";            $concatenate_media.= '<source src="' . $file_url . '" type="' . $audio_type[$file_format] . '">' . "n";            $concatenate_media.= '</audio>' . "n";        }        echo $concatenate_media;

needs working on to suit your needs, but its one way.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...