SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    May 2013
    Posts
    204
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    how with JavaScript & jQuery or PHP get media file duration eg video.mp4

    how with JavaScript & jQuery or PHP get media file duration eg video.mp4?

  2. #2
    SitePoint Addict bronze trophy WolfShade's Avatar
    Join Date
    Mar 2014
    Location
    St. Louis, MO, USA
    Posts
    332
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Just about any server-side script should be able to get at least the file size. Not sure about duration, though. It might be in the file meta-data, if PHP can access that.

    Found a SO post on this same question.

    HTH,

    ^_^

  3. #3
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,046
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    For HTML5 you should be able to use the video tag's duration property, once the file's metadata is loaded.

    Code:
    var myVideoPlayer = document.getElementById('video_player');
    myVideoPlayer.addEventListener('loadedmetadata', function() {
        console.log(videoPlayer.duration);
    });
    This gets triggered when the browser received all the meta data from the video.

    Reference

  4. #4
    SitePoint Addict bronze trophy WolfShade's Avatar
    Join Date
    Mar 2014
    Location
    St. Louis, MO, USA
    Posts
    332
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    HTML5 is nice, but I (personally) would hold off using HTML5 unless I had in place code that would gracefully degrade if the video tag isn't supported (big differences between IE8, IE9, IE10, FireFox, etc.)

    And I'm not sure (the OPs English doesn't seem native), but I suspect the OP wanted the information prior to the video being loaded. Just guessing.

    ^_^

  5. #5
    SitePoint Addict
    Join Date
    May 2013
    Posts
    204
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, I want to list the videos & duration without yet these go to player... Only server side option?

  6. #6
    SitePoint Addict bronze trophy WolfShade's Avatar
    Join Date
    Mar 2014
    Location
    St. Louis, MO, USA
    Posts
    332
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lse123 View Post
    Yes, I want to list the videos & duration without yet these go to player... Only server side option?
    Yes, only server-side. I'm assuming the media file will be on the server. Only a server-side script would be able to access the file and get that information.

    Unless the media file in question is on another server and a different domain (like YouTube.com, or similar.) In that case, the hosting service would have to do it.

    HTH,

    ^_^

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,046
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Howdy,

    Quote Originally Posted by WolfShade View Post
    HTML5 is nice, but I (personally) would hold off using HTML5 unless I had in place code that would gracefully degrade if the video tag isn't supported (big differences between IE8, IE9, IE10, FireFox, etc.)
    Sure, but that entirely depends on what you are working on, who it is intended for and so on.

    Quote Originally Posted by WolfShade View Post
    I suspect the OP wanted the information prior to the video being loaded. Just guessing.

    Quote Originally Posted by lse123 View Post
    Yes, I want to list the videos & duration without yet these go to player... Only server side option?
    I'm not quite sure what the OP's reply means.
    However, to demonstrate how it would work client-side, here is a demo.
    Maybe it helps, maybe not

  8. #8
    SitePoint Addict bronze trophy WolfShade's Avatar
    Join Date
    Mar 2014
    Location
    St. Louis, MO, USA
    Posts
    332
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    I'm not quite sure what the OP's reply means.
    It does require a bit of guessing. OP wants to list the title (or filename) and the duration (assuming in min:sec format) of each media file (MP3, MP4, WMV, etc.) - sort of like on YouTube - each thumbnail displays a frame of the video, with a small duration displayed in the lower right corner. OP did not say anything about thumbnails, so I'm assuming this will probably be a text display of file/duration for a user to click on so said user knows what they are clicking on.

    ^_^


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •