Embedding Audio and Video in CONTENTdm

Last modified Monday, May 11th, 2009

Adding the below code to your CONTENTdm files will enable flash video files and MP3s to be played within the web browser. It requires a flash player to be present on the server. We use the JW Flash player with a custom skin for audio. The JW Flash player home page can be visited here. There are three files for playing video: a Javascript file, the player itself, and a skin. Make sure to place the Javascript file, FLV player and its skin in the locations specified by lines 29 and 32 of embedall.php below. The default locations are \\cdminstall\docs\cdm4\includes\Scripts\ for the Javascript and \\cdminstall\docs\cdm4\includes\ for the skin and player.

Besides the software requirement, a metadata field must be added for multimedia items. The script expects the field to be named avsource and it needs to be an absolute URL to the media file. To decide whether to include the audio player or the video player, the script also checks for a field called format. Allowable values are "video" or anything with "audio" in it.

If you use our code, please email digital initiatives.

basic_view.php

  1. case "item_viewer.php":
  2. //Modification to embed audio and video by Peter Standard
  3.     $avsrc = $structure[$index['AVSOUR'][0]]["value"];
  4.     if(isset($structure[$index['FORMAT'][0]]["value"])) {
  5.         $format = $structure[$index['FORMAT'][0]]["value"];
  6.         if($format == "video" || strstr($format,"audio") !== FALSE) {
  7.             include("embedall.php");
  8.         }
  9.     }

embedall.php

  1. <?php
  2. $lq= "no"; // Set default quality. "no" is high quality, "yes" is low quality
  3. parse_str($_SERVER['QUERY_STRING']);
  4.  
  5. $querystring = $_SERVER['QUERY_STRING'];
  6. $querystring = str_replace("&lq=yes","",$querystring);
  7. $querystring = str_replace("&lq=no","",$querystring);
  8. if($CISOROOT=="/pnewsreels" || $CISOROOT=="/pulibraries") {
  9.     if($lq=="no") { ?>
  10. <p>If the video does not play smoothly, try the <a href="<?php echo($_SERVER['PHP_SELF'] . "?$querystring&lq=yes"); ?>">low quality version</a></p>
  11.  
  12. <?php }  if($lq=="yes") { ?>
  13. <p>If you have a high speed connection, try accessing the <a href="<?php echo($_SERVER['PHP_SELF'] ."?$querystring&lq=no"); ?>">high quality version</a></p>
  14.  
  15. <?php } } if(strstr($format,"audio") !== FALSE) { ?>
  16. <div align="center" id="main">
  17. <p style="text-align: center;">To begin playback, click the <img src="includes/playbutton.png" alt="Play Button" /> icon below.</p>
  18. <embed
  19. src="http://earchives.lib.purdue.edu/web/oralhistory/nice.swf"
  20. width="700"
  21. height="110"
  22. allowscriptaccess="always"
  23. allowfullscreen="true"
  24. flashvars="volume=99&height=110&width=700&file=<?=$avsrc?>"
  25. />
  26.  
  27. </div>
  28. <?php }  else { ?>
  29. <script src="includes/Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
  30. <div align="center" id="main">
  31. <script type="text/javascript">
  32. AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0','width','726','height','531','id','FLVPlayer','src','includes/FLVPlayer_Progressive','flashvars','&MM_ComponentVersion=1&skinName=includes/Halo_Skin_3&streamName=<? if($lq=="yes") { $avsrc = str_replace(".flv","lq.flv",$avsrc); }?><?=$avsrc?>&autoPlay=true&autoRewind=false','quality','high','scale','noscale','name','FLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','includes/FLVPlayer_Progressive' );
  33. </script>
  34. </div>
  35. <?php } ?>

Lines 134 through 139 are placed inside the "item_viewer.php" case in basic_view.php. The code sets a variable for the AV source field and the format. The format is necessary to check whether the embedded media player should be included and the AV source field contains the media file's URL. There are two Javascript files in addition to the media player for playing video.

This file has three different parts. The first part, from line 2 until line 15, creates a toggle for collections with high quality video and low quality video. Replace "/pnewsreels" in line 8, $CISOROOT=="/pnewsreels", with the collection alias of the collection with high and low quality video. Add more collections following the format of /pulibraries. Basically, add || $CISOROOT=="/othercoll" for as many as collections as you have high and low quality video. Both versions of the video should be placed in the same folder with the same filename, except the low quality version should have lq at the end of the filename. For example, if the AV Source field were http://earchives.lib.purdue.edu/web/newsreels/films/1980.flv, then the low quality version should be http://earchives.lib.purdue.edu/web/newsreels/films/1980lq.flv. To see the streaming video code in action, visit Purdue Newsreels.