Extra functions

manuman94 edited this page May 7, 2014 · 3 revisions

Getting handle values

The ytCropper library has methods to get values like the current play time, the video duration, and the video ID.

  • ytCropper::getVideoId()
    Returns the ID of the ytCropper assigned video.

  • ytCropper::getCurrentTime()
    Returns the current play time in seconds.

  • ytCropper::getDuration()
    Returns the loaded video duration in seconds.

Plus, it has helper functions that make it easier to show this information.

  • showWithTwoDigits(n)
    Returns a string with two digits for showing the date in MM:SS format. Example -> n = 9 -> Return = “09”.

  • toDefaultTime(seconds)
    Function used to convert seconds into minutes and seconds. Returns a JSON object with the minutes and seconds values. Example -> seconds = 130 -> Return = { minutes:2, seconds: 10}

Example:

$("#generateButton").on("click", function (e) {
    // Prevent the default behaviour of <a> tag
    e.preventDefault();

    // Put in the #firstInput the video ID
    $("#firstInput").val(cropper.getVideoId);
    // Put in the #secondInput the video duration in MM:SS format
    time = toDefaultTime(cropper.getDuration());
    string = showWithTwoDigits(time.minutes) + ":" + showWithTwoDigits(time.seconds);
    $("#secondInput").val(string);
    // Put in the #thirdInput the current play time in MM:SS format
    time = toDefaultTime(cropper.getCurrentTime());
    string = showWithTwoDigits(time.minutes) + ":" + showWithTwoDigits(time.seconds);
    $("#thirdInput").val(string);
});


This code put on the text input the video ID, video duration and current play time values, formatting dates to MM:SS for a clearly view.

You can test it here: http://jsfiddle.net/BxQhy/17/

More information about this plugin on this wiki.