0

My question yesterday was too broad on this subject, so I will be specific:

I teach music classes and at the end of the class, we record several short (30 second-3 minute) videos for the parts people are learning. Up until now, I have directly uploaded all those videos to my network attached storage (NAS). My students have access there. That works great for me, but it is difficult for the students because they need to download each video manually and then play from their computer.

Our school has a WordPress site, and I want to be able to send students to a password protected page where they log in and are presented with several folders (a folder for each song). When they open the folder, it takes them to a page that displays all the videos and the users can click on the video and play them directly from the browser.

I downloaded the WordPress iPhone app and tried to:

  1. create a page.
  2. Pick the videos from the phone
  3. Upload to the page
  4. publish.

This sort of works, but every other video is giving me an upload error (IE I think they are too big and time out) and it is very time consuming.

Part of the issue is how WordPress handles uploaded media in the library-since there is no subfolder, I don't see how to easily batch upload to specific pages.

I downloaded "Media File Manager", but that doesn't work because you have to first upload the files into the library and then move the files manually into the subfolders.

So there are the details. Now my question:

Is there a way to:

  1. Ppload individual videos into sub-folders in the upload folder (I can create the sub-folders with my FTP) (I already know how to do this.)
  2. Have individual pages that treat those subfolders as separate galleries.
  3. Have the page display all items in the gallery (as playable videos).
2
  • Please read into the help center: (Plugin) recommendations are off topic
    – kaiser
    Sep 20, 2013 at 18:58
  • Thanks for the edit @toscho, that should remedy the message from Kaiser. I don't see a way to +1 your edit, so thanks here....
    – Joel
    Sep 20, 2013 at 23:58

1 Answer 1

0

Maybe it's not necessary to add the files to the library. We can simply scan a given folder and print <video> tags with all the video files that we find.

If password is required, I'd give Subscriber accounts to the users and present the content in the backend. In each User profile, an administrator can select the folders that they'll have access to.

Here's a proof of concept supposing that:

  • We upload manually to sub-folders inside wp-content/videos/.

  • A user has access to wp-content/videos/chapter1/ and wp-content/videos/chapter2/.

  • Some solution is found to prevent external access to this folder/files.

<?php 
/* Plugin Name: Video Page for Subscribers */

add_action( 'admin_menu', 'admin_menu_wpse_114998' );

# Custom admin page
function admin_menu_wpse_114998()
{
    add_dashboard_page(
        'Video Library',
        'Video Library',
        'read', // visible to Subscribers
        'video-library',
        'menu_callback_wpse_114998'
    );
}

# Print the admin page
function menu_callback_wpse_114998()
{
    $paths = user_folders_wpse_114998( get_current_user_id() );
    foreach( $paths as $path )
        print_video_folder_wpse_114998( $path );
}

# Get the user's allowed folders
function user_folders_wpse_114998( $user_id )
{
    // $user_folders = do_your_thing_to_get_it();
    $user_folders = array( 'chapter1', 'chapter2' );
    return $user_folders;
}

# Iterate through a directory and print all MP4 videos
function print_video_folder_wpse_114998( $folder )
{
    $path = WP_CONTENT_DIR . '/videos/' . $folder;
    $files = array();
    $directory = new RecursiveDirectoryIterator( $path );
    $objects = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::SELF_FIRST );
    foreach( $objects as $name => $fileinfo )
    {
        if ( !$fileinfo->isFile() ) 
            continue;

        if( false === strpos( $name,'.mp4' ) )
            continue;

        $files[] = array(
            'url' => WP_CONTENT_URL . "/videos/$folder/" . $fileinfo->getFilename(),
            'name' => $fileinfo->getFilename()
        );
    }
    foreach( $files as $file )
    {
        ?>  <div style="margin:25px 25%;background-color:#cecece;text-align:center">
            <h2><?php echo $file['name']; ?></h2>
            <video src="<?php echo $file['url']; ?>" controls>
              Your browser does not support the <code>video</code> element.
            </video>
            </div>
        <?php
    }

}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.