spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column20


Audio Control Example Code

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Here is the code for the example on the previous page:

<SCRIPT LANGUAGE="JavaScript">
<!--

var NSsound = navigator.plugins && navigator.plugins["LiveAudio"];
var IEsound = navigator.plugins && document.all;
var audioEnabled = NSsound || IEsound;

if (!audioEnabled)
  document.write("Your browser does not support
   JavaScript-enabled audio control"); // join with previous line
if (!navigator.javaEnabled()) alert("Your browser is not Java-enabled.
Please edit preferences.");

onload = init;
timerID = null;

function init() {
  if (!navigator.javaEnabled()) return;
  if (!audioEnabled) return;
  document.display.soundcard.value = (IEsound) ?
document.audiopanel.isSoundCardEnabled() : "not supported";
  document.display.filename.value = (IEsound) ?
document.audiopanel.fileName : "not supported";
  endTime = (IEsound) ? 
document.audiopanel.selectionEnd : "not supported"; // global variable
  document.display.position.value =
    (IEsound) ? Math.floor(document.audiopanel.currentPosition) : 
       "not supported"; // join with previous line
  state();
}

function showPosition() {
  if (!navigator.javaEnabled()) return;
  if (!audioEnabled) return;
  document.display.position.value = (IEsound) ?
Math.floor(document.audiopanel.currentPosition) : "not supported";
  setTimeout("showPosition()", 1000);
}

function playIt() {
  if (!navigator.javaEnabled()) return;
  if (!audioEnabled) return;
  if (IEsound) document.audiopanel.play()
  else if (NSsound) document.audiopanel.play(true);
  state();
  timerID = setTimeout("showPosition()", 1000);
}

function stopIt() {
  if (!navigator.javaEnabled()) return;
  if (!audioEnabled) return;
  document.audiopanel.stop();
  state();
  clearInterval(timerID);
}

function pauseIt() {
  if (!navigator.javaEnabled()) return;
  if (!audioEnabled) return;
  document.audiopanel.pause();
  state();
  clearInterval(timerID);
}

function state() {
  if (!navigator.javaEnabled()) return;
  var field = document.display.state;
  if (IEsound) {
    var cur = document.audiopanel.currentState;
    if (cur == 0) field.value = "stopped";
    if (cur == 1) field.value = "paused";
    if (cur == 2) field.value = "playing";
  } else if (NSsound) {
      if (document.audiopanel.IsReady()) field.value = "stopped";
      if (document.audiopanel.IsPlaying()) field.value = "playing";
      if (document.audiopanel.IsPaused()) field.value = "paused";
  }
}

function toggleControls() {
  if (!navigator.javaEnabled()) return;
  if (IEsound)
    document.audiopanel.showControls = !document.audiopanel.showControls;
}

function startAtGivenSec(sec) {
  if (!navigator.javaEnabled()) return;
  if (IEsound)
    document.audiopanel.selectionStart = sec
  else if (NSsound)
         document.audiopanel.start_time(sec);
}

function stopAtGivenSec(sec) {
  if (!navigator.javaEnabled()) return;
  if (IEsound)
    document.audiopanel.selectionEnd = sec
  else if (NSsound)
    document.audiopanel.end_time(sec);
}

function stopAtEnd() {
  if (!navigator.javaEnabled()) return;
  if (IEsound)
    document.audiopanel.selectionEnd = endTime
  else if (NSsound)
    document.audiopanel.stop_at_end();
}

function decreaseVolume() {
  if (!navigator.javaEnabled()) return;
  if (IEsound)
    document.audiopanel.volume -= 10
  else if (NSsound)
    document.audiopanel.setvol(parseInt(document.audiopanel.GetVolume() - 10))
}

function increaseVolume() {
  if (!navigator.javaEnabled()) return;
  if (IEsound)
    document.audiopanel.volume += 10
  else if (NSsound)
    document.audiopanel.setvol(document.audiopanel.GetVolume() + 10)
}

function setDefaultVolume() {
  if (!navigator.javaEnabled()) return;
  if (IEsound)
    document.audiopanel.volume = 50
  else if (NSsound)
    document.audiopanel.setvol(50)
}

if (audioEnabled)
  document.write("<EMBED NAME='audiopanel' SRC='aladdin.mid' MASTERSOUND
    HEIGHT='60' WIDTH='144' HIDDEN='false'>") //join with previous line
else
  document.write("Your browser cannot play sound files.");
</SCRIPT>
<FORM NAME="display">
Sound card enabled: <INPUT TYPE="text" NAME="soundcard" SIZE="14"><BR>
State: <INPUT TYPE="text" NAME="state" SIZE="10"><BR>
Position: <INPUT TYPE="text" NAME="position" SIZE="14"><BR>
Filename: <INPUT TYPE="text" NAME="filename" SIZE="50"><BR>
<INPUT TYPE="button" VALUE="Play" onClick="playIt()">
<INPUT TYPE="button" VALUE="Pause" onClick="pauseIt()">
<INPUT TYPE="button" VALUE="Stop" onClick="stopIt()"><BR>
<INPUT TYPE="button" VALUE="Toggle Controls" onClick="toggleControls()"><BR>
<INPUT TYPE="button" VALUE="Start @ 10 Second" onClick="startAtGivenSec(10)">
<INPUT TYPE="button" VALUE="Stop @ 30 Second" onClick="stopAtGivenSec(30)"><BR>
<INPUT TYPE="button" VALUE="Start @ 0 Second" onClick="startAtGivenSec(0)">
<INPUT TYPE="button" VALUE="Stop @ End of Track" onClick="stopAtEnd()"><BR>
<INPUT TYPE="button" VALUE="<=====" onClick="decreaseVolume()">
<INPUT TYPE="button" VALUE="==^==" onClick="setDefaultVolume()">
<INPUT TYPE="button" VALUE="=====>" onClick="increaseVolume()"><BR>
</FORM>

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior

Created: June 19, 1998
Revised: May 16, 1999

URL: http://www.webreference.com/js/column20/liveaudiocode.html