music
OSdata.com: programming text book 

OSdata.com

start time

summary

    Advancing on the simple player, we look at how to trim the beginnings and ends of music videos.

license

    This is example code from This Side of Sanity, released under Apache License 2.0.

    Copyright 2012, 2013, 2014 Milo

    Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Google

summary

    Advancing on the simple player, we look at how to trim the beginnings and ends of music videos.

components used

    We use the same components as the simple player and it is an exercise for the programmer to add the new capability.

the problem

    Many music videos on YouTube (including official videos) have silence at the beginning and/or end, and some have narrative or other non-music portions before and/or after the music.

    In this lesson, we learn how to trim the videos to just the part we want to hear in our player.

start time

    When you view a YouTube video, there is a timer at the bottom of the screen (you may need to place the cursor over the bottom of the video to bring it into view).

    Watch for how much time passes before the music starts.

    Store this as your new $starttime.

    Adjust the total $songlength to subtract the $starttime (so the video doesn’t sit around silent that long at the end).

    You can further trim the $songlength to subtract silence or toher non-musical parts at the end of the video.

    Remember to set $starttime to 0 or empty string "" for any videos that you want to have start normally at the beginning. if you choose to use an empty string, that will match storing NULL in your SQL data base, while the zero will match storing an actual numeric zero in your SQL data base. The choice is yours. both methods work.

    I use the double quotes "" for an empty string simply because at a glance two single quotes in a row (monospace) '' or (proportional) '' can look like one double quote. I do this to prevent confusion, because confusion leads to programming errors.

    The music video “Walk” by the Foo Fighters is a good example, because it has acting portions both before and after the actual music portion.

    case 2 :
      $youtubecode = '4PkcfQtibmU';
      $songlength = '262';
      $starttime = '63';
      $songtitle = 'Walk';
      $songartist = 'the Foo Fighters';
      $description = 'This was the 2011 Grammy rock song.';
      break;

create the correct GET for the embed

    In all cases where there is a $starttime, you need to create the correct GET string to add to the embed code.

    Use the following example if you chose to use empty string to indicate starting at the normal beginning of the music video.

if ($starttime != "")
  $starttag = '&start='.$starttime;
else
  $starttag = "";

    Or use the following example if you chose to use numeric zero to indicate starting at the normal beginning of the music video.

    Note that in the second example, you test $starttime for numeric zero, but set your $starttag to the empty string, because you will be inserting a string into the embed code.

if ($starttime != 0)
  $starttag = '&start='.$starttime;
else
  $starttag = "";

adding start time to embedded video

    Now adjust your embed code to indicate the start time for the video (highlighted in red).

echo "<p align=\"center\"><object style=\"height: 390px; width: 640px\"><param name=\"movie\" value=\"http://www.youtube.com/v/".$youtubecode.$starttag."?version=3&autoplay=1&rel=0&feature=player_embedded\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowScriptAccess\" value=\"always\"><embed src=\"http://www.youtube.com/v/".$youtubecode .$starttag."?version=3&autoplay=1&rel=0&feature=player_embedded\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"640\" height=\"360\"></object>\n";

done

    Once you have made these adjustments to your music video player, you will have improved the listening experience.

see full player in action

return to explanation of simple player

contact
comments, suggestions, corrections, criticisms

please contact us

your name:
email address:
phone number:
message:

return to table of contents
free downloadable college text book

previous page next page
previous page next page

Google


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2011, 2012 Milo

    Created: February 14, 2012 (using code started in September 2011)

    Last Updated: February 16, 2012


return to table of contents
free downloadable college text book

previous page next page
previous page next page