etsted Posted April 29, 2014 Share Posted April 29, 2014 (edited) 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 April 29, 2014 by etsted Link to comment Share on other sites More sharing options...
dsonesuk Posted April 29, 2014 Share Posted April 29, 2014 IF you have placed the $file_url as above, it won't work because php works from top to bottom, it will try to echo $file_url but has no reference to it yet!, so it will come up as undefined. Link to comment Share on other sites More sharing options...
etsted Posted April 29, 2014 Author Share Posted April 29, 2014 that has nothing to with that case, ofcourse the $file_url is above my video tag! Besides, do i need to specify the type attribute when i use video tag og audio tag? Link to comment Share on other sites More sharing options...
dsonesuk Posted April 29, 2014 Share Posted April 29, 2014 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 More sharing options...
etsted Posted April 29, 2014 Author Share Posted April 29, 2014 my code doesnt work, if i specify a type attribute, any suggestions? Link to comment Share on other sites More sharing options...
dsonesuk Posted April 29, 2014 Share Posted April 29, 2014 With what you giving us? NO! Link to comment Share on other sites More sharing options...
etsted Posted April 30, 2014 Author Share Posted April 30, 2014 // 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 More sharing options...
dsonesuk Posted April 30, 2014 Share Posted April 30, 2014 Why are you using audio type for what is obviously a video format is the first question. Link to comment Share on other sites More sharing options...
etsted Posted April 30, 2014 Author Share Posted April 30, 2014 i have different files in the DB, also do i need to specify the type? Link to comment Share on other sites More sharing options...
etsted Posted April 30, 2014 Author Share Posted April 30, 2014 its an mp4 movie Link to comment Share on other sites More sharing options...
dsonesuk Posted April 30, 2014 Share Posted April 30, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now