Detect the mime type and call FlowPlayer

Hello again,

I'm working on integrating FlowPlayer into an Omeka theme and have it running nicely. The only problem is that right now, I'm calling FlowPlayer based on Item Type using the item_has_type()helper. Since my/many sites have mixed types of multimedia files for any given Item Type (mpeg, wmv, flv, etc), I need to narrow it down so that FlowPlayer only comes into play for supported formats.

Can anyone help me out with this one? Basically, I need to modify the code below.

<?php
			//if image --> Lightbox...
		    if (item_has_thumbnail())
					{
					echo '<p><em>Click the Image for Full Size</em></p>';
					echo display_files_for_item(array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));
					foreach ($item->Files as $file){
					echo '<div style="clear:both;">Download: <a href="'. file_download_uri($file). '" class="download-file">'. $file->original_filename. '</a></div> ';
					}
										}
			//if supported video -->Flowplayer...
			elseif (item_has_type('Moving Image'))
					{
					foreach ($item->Files as $file) {
					echo '<a href="'. file_download_uri($file). '" class="download-file" id="player" style="display:block;width:315px;height:300px;background:#555;border:3px double #fff;"></a>';
					echo '<script>flowplayer("player", "'.WEB_ROOT.'/themes/berlinGallery/common/flowplayer/flowplayer-3.2.2.swf");</script>';
					echo '<div style="clear:both;">Download: <a href="'. file_download_uri($file). '" class="download-file">'. $file->original_filename. '</a></div> ';
					}
					}
			//if any other...
			else
				{
				echo display_files_for_item();
				}
			?>

Thanks,

Erin

Have you seen the Steel Navy site, it uses FlowPlayer, http://www.steelnavy.org/history/?

Maybe Dave Colamaria can help.

Hi Shiela,

I actually looked at Dave's code and I think he has manually coded that video into the homepage independent of Omeka.

Once you have a File object, you can call $file->getMimeType() to get at the MIME type for that specific file.

So, you could do something like:

// Array of MIME types FlowPlayer supports
$flowPlayerTypes = array('video/mp4', etc...);

foreach ($item->Files as $file) {
// Checks if the mime-type of the file is one of FlowPlayer's supported types
if ( array_search($file->getMimeType, $flowPlayerTypes) !== false ) {
// flowplayer echo code here
}
}

Thanks John,

It took me a while to realize how that actually works, but for the record, here's what I did:

Looped the item files to extract the mime type to use later...

<?php while(loop_files_for_item()):
	//retreive the mimetype...
        $file = get_current_file();
		$filemime=$file->getMimeType();
		$flowplayer_flash='video/x-flv';
		$qtaudio_mp3='audio/mpeg';
		?>
    <?php endwhile; ?>

And then tested against the mime type and some other conditions...

<?php
			//if image --> Lightbox with download link...
		    if (item_has_thumbnail())
					{
					echo '<p><em>Click the Image for Full Size</em></p>';
					echo display_files_for_item(array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));
					foreach ($item->Files as $file){
					echo '<div style="clear:both;padding:2px;">Download: <a href="'. file_download_uri($file). '" class="download-file">'. $file->original_filename. '</a> ('.$filemime.')</div> ';
					}
										}
			//if supported video -->Flowplayer with download link...
			elseif ($filemime==$flowplayer_flash)
					{
					foreach ($item->Files as $file) {
					echo '<a href="'. file_download_uri($file). '" class="download-file" id="player" style="display:block;width:315px;height:300px;background:#555;border:3px double #fff;"></a>';
					echo '<script>flowplayer("player", "'.WEB_ROOT.'/themes/berlinGallery/common/flowplayer/flowplayer-3.2.2.swf");</script>';
					echo '<div style="clear:both;">Download: <a href="'. file_download_uri($file). '" class="download-file">'. $file->original_filename. '</a> ('.$filemime.')</div> ';
					}
					}
			//if mp3 --> Quicktime Player with download link...
			elseif ($filemime==$qtaudio_mp3)
					{
					echo display_files_for_item();
					echo '<div style="clear:both;">Download: <a href="'. file_download_uri($file). '" class="download-file">'. $file->original_filename. '</a> ('.$filemime.')</div> ';
					} 

			//if any other...
			else
				{
				echo display_files_for_item();
				}
			?>

Still working on taking advantage of this as you can see but I thought it might be useful to post anyway.

Great. Sorry about any confusion, I could've explained exactly what was going on a little more clearly.

I do want to note that the code you've posted, which first loops through all the files, then performs some checks afterwards, will only work correctly as long as every file for a given Item has the same mime-type, or if you only have one file for each Item.

If this is true for your installation, you can "get away" with this. If you do have to deal with varying file types within an Item, then you need to move your code that actually displays the files into the loop_files_for_item loop (and use functions like display_file instead of display_files_for_item).