Foliovision › Forums › FV Player Pay Per View › Requests and Feedback › dynamic linking to video time position
-
bsd
i need to have a dynamic url created by a plugin that add to the url the time to be played.
but i see in the link there is a ID like this:
https://meirtv.com/shiurim/350752/#fvp_1085427345,7m00s
I dont know how this 1085427345 id is generated, but as i have only one video per page, it would be good to ma ke something like:
https://meirtv.com/shiurim/350752/&time=7m00s
to work…
any solutions?
-
-
Hello Meir,
Since you are not using the FV Player database,
1085427345
is the video file name without the extension.I see that if FV Player could simply take the first player on the page and play it at a given timestamp it would be an easier solution.
However in that case it would need extra logic to skip the video ad and also to be able to target individual videos in the playlists.
Please let us know if that makes sense.
It seems it would be also harder to keep track of what video you are really trying to link to at that timestamp. Please let us know about the exact use case for these links.
Thanks,
MartinHello Meir,
Thank you for the details.
We need some time before we decide what’s the right thing to do for FV Player. Perhaps we would like these video links to target the first video on the page by default, but if we decide to do so we must stick to that behavior and not change our minds in the future.
Thanks,
Martinok, i developed a solution by myself…
the folowwing snippet seeks to timestamp for example:
https://meirtv.com/shiurim/244997/?time=33m27s
and if there is no “time” parameter, it will seek by fv player default (last watched etc)// FV Player Time Parameter Support (Updated) // Add this to your theme's functions.php or a code snippets plugin. // --- 1. Enqueue the JavaScript Handler --- // This script now only acts if a 'time' parameter is in the URL. function fvpt_enqueue_scripts() { // Only run this on single posts and pages where videos are likely to be. if (is_singular()) { $script = ' jQuery(document).ready(function($) { // Get the time parameter directly from the page\'s URL. const urlParams = new URLSearchParams(window.location.search); const timeParam = urlParams.get("time"); // CRITICAL FIX: Only run the seeking logic if a "time" parameter // actually exists in the URL. If it doesn\'t, this entire block is // skipped, allowing FV Player\'s default behavior (like "last watched") to work. if (timeParam) { // Function to parse time formats like "1h30m10s" or "90" into seconds. const parseTimeParam = (timeStr) => { if (!timeStr) return 0; let totalSeconds = 0; const regex = /(\d+)([hms])/g; let match; while ((match = regex.exec(timeStr)) !== null) { const value = parseInt(match[1], 10); const unit = match[2]; switch(unit) { case "h": totalSeconds += value * 3600; break; case "m": totalSeconds += value * 60; break; case "s": totalSeconds += value; break; } } // Fallback for plain seconds format (e.g., "?time=125") if (totalSeconds === 0 && /^\d+$/.test(timeStr)) { totalSeconds = parseInt(timeStr, 10); } return totalSeconds; }; const seekTime = parseTimeParam(timeParam); // Only seek if the time is greater than 0. if (seekTime > 0) { const applySeek = (api) => { // The "ready" event ensures the video is loaded enough to seek. api.on("ready", function() { // This small timeout ensures our seek command runs after // any initial player logic. setTimeout(() => { api.seek(seekTime); }, 150); }); }; // Hook into the FV Player API (supports V7+ and older versions). if (typeof flowplayer !== "undefined") { flowplayer((api, root) => { applySeek(api); }); } else if ($(".flowplayer").length) { $(".flowplayer").each(function() { const api = $(this).data("flowplayer"); if (api) { applySeek(api); } }); } } } }); '; // Use wp_add_inline_script to safely add the JavaScript. wp_add_inline_script('jquery-core', $script); } } add_action('wp_enqueue_scripts', 'fvpt_enqueue_scripts'); // --- 2. Add rewrite rule for pretty URLs (Optional) --- // This allows for URLs like /shiurim/123/time/1m30s/ function fvpt_add_rewrite_rules() { add_rewrite_rule( '^shiurim/([0-9]+)/time/([0-9hms]+)/?$', 'index.php?p=$matches[1]&time=$matches[2]', // We now use 'time' consistently. 'top' ); } add_action('init', 'fvpt_add_rewrite_rules'); // --- 3. Shortcode to easily generate time-based links --- // Usage: [fv_time_link time="1m30s" text="Watch from 1:30"] function fvpt_time_link_shortcode($atts) { $atts = shortcode_atts(array( 'time' => '0', 'text' => 'Watch from here', 'class' => 'fv-time-link' ), $atts, 'fv_time_link'); // Use WordPress\'s add_query_arg to safely build the URL. $url = add_query_arg('time', esc_attr($atts['time']), get_permalink()); return sprintf( '<a href="%s">%s</a>', esc_url($url), esc_attr($atts['class']), esc_html($atts['text']) ); } add_shortcode('fv_time_link', 'fvpt_time_link_shortcode'); // --- Helper function to get a time link programmatically --- function fvpt_get_time_link($time = '0m00s') { return add_query_arg('time', $time, get_permalink()); }