• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Foliovision

  • Weblog
    • FV Player
    • WordPress
    • Video of the Week
    • Case Studies
    • Business
  • About
    • Testimonials
    • Meet the Team
    • We Support
    • Careers
    • Contact
    • Pricing
  • Products
  • Support
    • FV Player Docs
    • Pro Support
  • Login
  • Basket is empty

FV Flowplayer Playlist search

Foliovision › Forums › FV Player › How to … › FV Flowplayer Playlist search

  • D.C. D. 1 year, 8 months ago

    Hi! So I have constructed a search field for my FV Flowplayer. It works as needed for everything EXCEPT – After searching for a video and then deleting the search term and clicking on a SELF-HOSTED video the controls don’t work and the loading animation is present whole time.

    I know this isn’t something you support – but I was hoping you might have a hint of what i should tell ChatGPT to look for to reapply the controls after we unload the search. — here’s a page with it on – https://dcdouglas.com/actor-film-television-videos-demo-reel/indie-film/ — a self hosted video is the Drowning in secrets.

    Here is the javascript:

    jQuery(document).ready(function($) {
        var flowPlayer = null; // Store the reference to the FlowPlayer instance
        var isPlaying = false; // Flag to prevent multiple click handling
        var controlsInitialized = false; // Flag to track if controls are initialized
    
        function destroyFlowPlayer() {
            if (flowPlayer) {
                try {
                    console.log('Destroying FlowPlayer', flowPlayer);
                    flowPlayer.unload();
                    flowPlayer = null;
                    console.log('FlowPlayer destroyed');
                } catch (error) {
                    console.error('Error destroying FlowPlayer:', error);
                }
            }
        }
    
        function initializeFlowPlayer() {
            return new Promise((resolve, reject) => {
                var checkInterval = setInterval(() => {
                    var player = $('.flowplayer').data('flowplayer');
                    if (player) {
                        flowPlayer = player;
                        clearInterval(checkInterval);
                        console.log('FlowPlayer initialized', player);
                        console.log('FlowPlayer config', player.conf);
                        resolve(flowPlayer);
                    }
                }, 500);
            });
        }
    
        function reinitializeSelfHostedVideo(player) {
            if (!controlsInitialized && player.video && player.video.sources[0].type === 'video/mp4') {
                // Explicitly reinitialize controls for self-hosted videos
                player.ui.createSubtitleControl();
                player.ui.setActiveSubtitleItem();
                controlsInitialized = true;
                console.log('Self-hosted video controls reinitialized');
            }
        }
    
        function attachControlListeners(player) {
            player.on('pause', function() {
                console.log('Video paused');
            });
            player.on('mute', function() {
                console.log('Video muted');
            });
            player.on('resume', function() {
                console.log('Video resumed');
            });
            player.on('unmute', function() {
                console.log('Video unmuted');
            });
            player.on('ready', function() {
                console.log('Video ready');
                reinitializeSelfHostedVideo(player); // Reinitialize controls for self-hosted videos
            });
            player.on('unload', function() {
                console.log('Video unloaded');
            });
            player.on('finish', function() {
                console.log('Video finished');
            });
        }
    
        function unloadCurrentVideo(player) {
            return new Promise((resolve, reject) => {
                console.log('Unloading current video');
                try {
                    player.unload();
                    console.log('Current video unloaded');
                    resolve();
                } catch (error) {
                    console.error('Error unloading video:', error);
                    reject(error);
                }
            });
        }
    
        function playVideo(videoId) {
            if (isPlaying) return; // Prevent multiple clicks
    
            isPlaying = true; // Set the flag to true
            console.log('Preparing to play video ID:', videoId);
    
            initializeFlowPlayer().then(player => {
                if (player && typeof player.play === 'function') {
                    var playlist = player.conf.playlist || [];
                    var videoIndex = playlist.findIndex(video => video.id == videoId);
    
                    if (videoIndex !== -1) {
                        unloadCurrentVideo(player).then(() => {
                            console.log('Playing video at index:', videoIndex);
                            player.play(videoIndex);
                            attachControlListeners(player); // Ensure controls are attached
                            isPlaying = false; // Reset the flag after playing
                        }).catch((error) => {
                            console.error('Error unloading video:', error);
                            isPlaying = false; // Reset the flag if error
                        });
                    } else {
                        console.error('Video ID not found in FlowPlayer playlist');
                        isPlaying = false; // Reset the flag if error
                    }
                } else {
                    console.error('FlowPlayer instance not found or play method not available');
                    isPlaying = false; // Reset the flag if error
                }
            }).catch((error) => {
                console.error('Error initializing FlowPlayer:', error);
                isPlaying = false; // Reset the flag if error
            });
        }
    
        function updatePlaylist(query) {
            var $playlist = $('.fv-playlist-slider-wrapper .fp-playlist-external a');
    
            if (query === "") {
                $playlist.show();
            } else {
                $playlist.each(function() {
                    var $this = $(this);
                    var title = $this.find('h4 span').text().toLowerCase();
    
                    if (title.includes(query)) {
                        $this.show();
                    } else {
                        $this.hide();
                    }
                });
            }
    
            // Scroll the playlist container back to the beginning
            $('.fv-playlist-slider-wrapper').scrollLeft(0);
        }
    
        $('#video-search').on('input', function() {
            var query = $(this).val().toLowerCase();
            updatePlaylist(query);
    
            if (flowplayer) {
                reinitializeSelfHostedVideo(flowplayer); // Reinitialize controls for self-hosted videos
            }
        });
    
        $('.fv-playlist-slider-wrapper .fp-playlist-external a').off('click').on('click', function(e) {
            e.preventDefault();
            e.stopImmediatePropagation(); // Prevent any additional handlers from being triggered
    
            var clickedItem = $(this);
            var videoId = clickedItem.data('item').id;
    
            console.log('First click on playlist');
            console.log('Clicked video ID:', videoId);
    
            // Ensure only one click is processed
            if (!isPlaying) {
                playVideo(videoId);
            } else {
                console.log('Already processing a video click');
            }
        });
    
        // Initial initialization of FlowPlayer
        initializeFlowPlayer().then(player => {
            if (player && typeof player.play === 'function') {
                attachControlListeners(player);
            }
        }).catch((error) => {
            console.error('Error initializing FlowPlayer on document ready:', error);
        });
    });

    And the PHP

    <?php
    
    // Enqueue necessary scripts
    function custom_video_search_enqueue_scripts() {
        wp_enqueue_script('custom-video-search', plugin_dir_url(__FILE__) . 'custom-video-search.js', array('jquery'), null, true);
    }
    add_action('wp_enqueue_scripts', 'custom_video_search_enqueue_scripts');
    
    // Create the shortcode
    function custom_video_search_shortcode($atts) {
        ob_start();
        ?>
        <div class="custom-video-search">
            <input type="text" id="video-search" placeholder="Search videos...">
        </div>
        <?php
        return ob_get_clean();
    }
    add_shortcode('video_search', 'custom_video_search_shortcode');
    
    // Ensure no whitespace is outputted before the XML declaration
    function custom_video_search_init() {
        ob_start(); // Start output buffering
    }
    add_action('init', 'custom_video_search_init');
    
    function custom_video_search_shutdown() {
        ob_end_flush(); // End output buffering and flush the output
    }
    add_action('shutdown', 'custom_video_search_shutdown');
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • D.C. D. 2 years ago

    After further testing, it appears that if I play a Youtube video first and then play a self-hosted video, the controls are non-clickable and they remain and the loading animation stays. The only thing to do is watch video or click away.

    Martin 2 years ago

    Hello D.C.,

    I’m checking with Alec if we would like to have a playlist search function right in core FV Player.

    Please test the issue with YouTube and MP4 videos (I guess you are self-hosting an MP4 video) in playlist without the search function. I was not able to run into a loading issue with such combination of videos in playlist.

    However I did notice that when I play the YouTube video after MP4 it plays without sound and I need to tap again for it to became audible.

    Thanks,
    Martin

    Alec Kinnear 2 years ago
    Avatar photo

    Hi DC,

    Love your acting showreel page. That search works great!

    We’re thinking hard about adding playlist search. If we did, it would just be an extra shortcode to put wherever you want on the page [fvplaylistsearch].

    Making the web work for you, Alec

Viewing 3 replies - 1 through 3 (of 3 total)
Reply To: FV Flowplayer Playlist search



Please Sign in or Register to upload files.

Related Posts

  1. adjust playlist font size on mobile

    adjust playlist font size on mobile

  2. YouTube/self-hosted mixed playlist

    YouTube/self-hosted mixed playlist

  3. YouTube playlist glitch

    YouTube playlist glitch

Primary Sidebar

How to …

    Categories

    • Business
    • Camera Reviews
    • Case Studies
    • Design
    • FV Player
    • Internet Marketing
    • IT
    • Life
    • SEO
    • Slovak
    • Video of the Week
    • WordPress

    Footer

    Our Plugins

    • FV WordPress Flowplayer
    • FV Thoughtful Comments
    • FV Simpler SEO
    • FV Antispam
    • FV Gravatar Cache
    • FV Testimonials

    Free Tools

    • Pandoc Online
    • Article spinner
    • WordPress Password Finder
    • Delete LinkedIn Account
    • Responsive Design Calculator
    Foliovision logo
    All materials © 2026 Foliovision s.r.o. | Panská 12 - 81101 Bratislava - Slovakia | info@foliovision.com
    • This Site Uses Cookies
    • Privacy Policy
    • Terms of Service
    • Site Map
    • Contact
    • Tel. ‭+421 2/5292 0086‬