Tag Archive for audio

Adjust Volume on FLV Video

var st:SoundTransform = new SoundTransform();
st.volume = 1;
stream.soundTransform = st;

function mute(e:MouseEvent):void {
st.volume = 0;
stream.soundTransform = st; // must reconnect after each volume change
}

source

Split media with mplayer

mencoder -endpos 49mb -o RobotPart1.avi ~/Movies/Robot.Chicken.S03E09.avi  -oac copy -ovc copy

source

Dump audio and video streams

# record audio stream
#
mplayer -cache 128 -vc dummy -vo null -ao pcm:file=raw.pcm "rtsp://realaudio.rferl.org/ch9/2007/04/19/20070419-013000-TA-program.rm?start=22:43&end=29:58"
#
# -vc dummy -vo null to ignore video

# encode to mp3
#
lame -b 32 -m m -f --tt "Micro 14/09/2007" raw.pcm ra20070419.mp3
lame -h --tt "Micro 14/09/2007" raw.pcm ra20070419.mp3
# tags are not utf-8 !

# record video stream
#
mplayer -dumpstream -dumpfile g20070427.wmv <a href="mms://vipmms.canalplus.fr/canalplus/guignols_070427_a.wmv" >mms://vipmms.canalplus.fr/canalplus/guignols_070427_a.wmv</a>
#
# transcode to mpeg4
#
mencoder g20070427.wmv -oac faac -ovc x264 -o g20070427.mp4

source

Music Playlist

<object id="darkplayer" codeBase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" type="application/x-oleobject" height="0" standby="Loading Microsoft Windows Media Player components..." width="0" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">
<param NAME VALUE>
<param NAME="ShowControls" VALUE="0">
<param NAME="ShowStatusBar" VALUE="0">
<param NAME="ShowDisplay" VALUE="0">
<param NAME="DefaultFrame" VALUE="Slide">
<param NAME="Autostart" VALUE="1">
<param NAME="Loop" VALUE="True">
</object>
<form name="form">
<select name="playlist" size="1">
<!-- Add song info here -->
<option value="0">SONG TITLE-ARTIST NAME</option>
<option value="1">SONG TITLE-ARTIST NAME</option>
<option value="2">SONG TITLE-ARTIST NAME</option>
<option value="3">SONG TITLE-ARTIST NAME</option>
<option value="4">SONG TITLE-ARTIST NAME</option>
<option value="5">SONG TITLE-ARTIST NAME</option>
</select><br>
<input TYPE="BUTTON" NAME="darkplay" VALUE="play" OnClick="play(document.forms['form'].playlist);">
<input TYPE="BUTTON" NAME="darkpause" VALUE="pause" OnClick="document.darkplayer.pause(); playstate=2;">
<input TYPE="BUTTON" NAME="darkstop" VALUE="stop" OnClick="document.darkplayer.stop(); playstate=2;"></p>
</form>
<script language="JavaScript">
<!--
var playstate = 1;
shuffle = 1;  // Set to 0 to always play first song in list
// Set to 1 to randomly choose the first song to play
songs=new Array();
// Add song URLs here
songs[0]="SONG URL";
songs[1]="SONG URL";
songs[2]="SONG URL";
songs[3]="SONG URL";
songs[4]="SONG URL";
songs[5]="SONG URL";
if (shuffle == 1) {
var randsg = Math.floor(Math.random()*songs.length);
document.darkplayer.FileName = songs[randsg];
document.darkplayer.scr = songs[randsg];
document.forms['form'].playlist.options[randsg].selected = true;
}
function play(list) {
if (playstate == 2) {
document.darkplayer.Play();
} else {
var snum = list.options[list.selectedIndex].value
document.darkplayer.FileName = songs[snum];
document.darkplayer.scr = songs[snum];
}
playstate = 1;
}
//-->
</script>

source

Music Player

<!-- start code provided by createblog.com -->
<script language="JavaScript"><!--
//script made by hoogli modified by Paul D
tips = new Array(3);
tips[0]="URL 1";
tips[1]="URL 2";
tips[2]="URL 3";
index=Math.floor(Math.random() * tips.length);
document.write("<embed src="+tips[index]+" showcontrols=0 height=0 width=0></embed>")
//--></script>
<!-- end code provided by createblog.com -->

source

Python – Get id3 from MP3 File

def getID3(filename):
fp = open(filename, 'r')
fp.seek(-128, 2)

fp.read(3) # TAG iniziale
title   = fp.read(30)
artist  = fp.read(30)
album   = fp.read(30)
anno    = fp.read(4)
comment = fp.read(28)

fp.close()

return {'title':title, 'artist':artist, 'album':album, 'anno':anno}

source

windows

// Con queste definizioni dico che tutti i frame e i dialog prendono il tema Metal
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
//

try
{
// Con questa imposto il tema
UIManager.setLookAndFeel(new MetalLookAndFeel());
}
catch(UnsupportedLookAndFeelException e)
{
e.printStackTrace();
}
// In questo modo tutte le finestre avranno il tema Metal

source

Java – Mini Lettore Wav

package Multimedia;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.MetalLookAndFeel;

public class AudioSystem
{
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);

try
{
UIManager.setLookAndFeel(new MetalLookAndFeel());
}
catch(UnsupportedLookAndFeelException e)
{
e.printStackTrace();
}

new AudioGUI();
}
}

package Multimedia;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class AudioGUI extends JFrame implements WindowListener
{
public AudioGUI()
{
this.setTitle("AudioSystem");
this.setSize(240, 100);
this.setResizable(false);

this.addWindowListener(this);

Container gc = this.getContentPane();
gc.add(new AudioGUIPan());

this.setVisible(true);
}

public void windowOpened(WindowEvent e)
{

}

public void windowClosing(WindowEvent e)
{
System.exit(0);
}

public void windowClosed(WindowEvent e)
{

}

public void windowIconified(WindowEvent e)
{

}

public void windowDeiconified(WindowEvent e)
{

}

public void windowActivated(WindowEvent e)
{

}

public void windowDeactivated(WindowEvent e)
{

}
}

class AudioGUIPan extends JPanel implements ActionListener
{
private JButton play;
private JButton stop;
private JButton loop;
private JButton open;
private JButton close;

private JFileChooser jfc;

private String file;

private AudioDevice ad;

public AudioGUIPan()
{
play = new JButton("Play");
play.addActionListener(this);
stop = new JButton("Stop");
stop.addActionListener(this);
open = new JButton("Open");
open.addActionListener(this);
close = new JButton("Close");
close.addActionListener(this);

this.add(stop);
this.add(play);
this.add(open);
this.add(close);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource() == close)
{
System.exit(0);
}
else if(e.getSource() == open)
{
jfc = new JFileChooser();
jfc.setFileFilter(new AudioFilter());

if(jfc.showOpenDialog(this) != JFileChooser.CANCEL_OPTION)
{
file = jfc.getSelectedFile().getAbsolutePath();
ad = new AudioDevice(new File(file));
}
}
else if(e.getSource() == play)
{
if(ad != null)
ad.play();
}
else if(e.getSource() == stop)
{
if(ad != null)
ad.stop();
}
}
}

package Multimedia;
import java.io.File;

import javax.swing.filechooser.FileFilter;

public class AudioFilter extends FileFilter
{
public boolean accept(File f)
{
return f.getName().toLowerCase().endsWith(".wav") || f.isDirectory();
}

public String getDescription()
{
return "Audio File *.wav";
}
}

package Multimedia;

import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;

public class AudioDevice implements AudioClip
{
private AudioClip ac;
public AudioDevice(File f)
{
try
{
ac = Applet.newAudioClip(f.toURL());
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}

public void play()
{
ac.play();
}

public void stop()
{
ac.stop();
}

public void loop()
{

}
}

source

Java – Example Very Simple Player (JMF)

package org.jmf.example;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.MetalLookAndFeel;

public class ExampleJMF
{
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);

try
{
UIManager.setLookAndFeel(new MetalLookAndFeel());
}
catch(UnsupportedLookAndFeelException e)
{
e.printStackTrace();
}

new exampleFrame();
}
}

package org.jmf.example;

import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

public class exampleFrame extends JFrame
{
private static final long serialVersionUID = 1L;

public exampleFrame()
{
super("JMF - Example...");

setSize(400, 300);
setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - getWidth())/2, (Toolkit.getDefaultToolkit().getScreenSize().height - getHeight())/2);

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});

setContentPane(new examplePanel());
setVisible(true);
}
}

package org.jmf.example;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import javax.swing.JPanel;

public class examplePanel extends JPanel implements ActionListener, ControllerListener
{
private static final long serialVersionUID = 1L;

private Component visualComponent;
private Player player;

public examplePanel()
{
try
{
player = Manager.createPlayer(new URL("file:///tmp/a.mpg"));
player.addControllerListener(this);

player.start();
}
catch(NoPlayerException e)
{
e.printStackTrace();
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}

public void paintComponent(Graphics g)
{
super.paintComponent(g);
}

public void actionPerformed(ActionEvent e)
{

}

public void controllerUpdate(ControllerEvent c)
{
if(player == null)
return;

if(c instanceof RealizeCompleteEvent)
{
if((visualComponent = player.getVisualComponent()) != null)
add(visualComponent);
}
}
}

source

Java – JMF Simple Filter

import java.awt.Dimension;

import javax.media.Buffer;
import javax.media.Effect;
import javax.media.Format;
import javax.media.ResourceUnavailableException;
import javax.media.format.RGBFormat;

public class SimpleFilter implements Effect
{
protected Format inputFormat = null;
protected Format outputFormat = null;

protected Format[] inputFormats = null;
protected Format[] outputFormats = null;

public AngelMotionCodec()
{
inputFormats = new Format[]{ new RGBFormat(null, Format.NOT_SPECIFIED, Format.byteArray, Format.NOT_SPECIFIED, 24, 3, 2, 1, 3, Format.NOT_SPECIFIED, Format.TRUE, Format.NOT_SPECIFIED) };
outputFormats = new Format[]{ new RGBFormat(null, Format.NOT_SPECIFIED, Format.byteArray, Format.NOT_SPECIFIED, 24, 3, 2, 1, 3, Format.NOT_SPECIFIED, Format.TRUE, Format.NOT_SPECIFIED) };
}

/****** Codec ******/
public Format[] getSupportedInputFormats()
{
return inputFormats;
}

public Format[] getSupportedOutputFormats(Format input)
{
if(input != null)
{
if(matches(input, inputFormats) != null)
return new Format[]{ outputFormats[0].intersects(input) };
else
return new Format[0];
}

return outputFormats;
}

public int process(Buffer input, Buffer output)
{
// Swap tra input & output
Object tmp = input.getData();

input.setData(output.getData());
output.setData(tmp);

return BUFFER_PROCESSED_OK;
}

public Format setInputFormat(Format input)
{
inputFormat = input;

return input;
}

public Format setOutputFormat(Format output)
{
if(output != null || matches(output, outputFormats) != null)
{
RGBFormat inRGB = (RGBFormat) output;

Dimension size = inRGB.getSize();
int maxDataLength = inRGB.getMaxDataLength();
int lineStride = inRGB.getLineStride();
int flipped = inRGB.getFlipped();

if(size == null)
return null;

if(maxDataLength < size.width*size.height*3)
maxDataLength = size.width*size.height*3;

if(lineStride < size.width*3)
lineStride = size.width*3;

if(flipped != Format.FALSE)
flipped = Format.FALSE;

outputFormat = outputFormats[0].intersects(new RGBFormat(size, maxDataLength, inRGB.getDataType(), inRGB.getFrameRate(), inRGB.getBitsPerPixel(), inRGB.getRedMask(), inRGB.getGreenMask(), inRGB.getBlueMask(), inRGB.getPixelStride(), lineStride, flipped, inRGB.getEndian()));

return outputFormat;
}

return null;
}
/****** Codec ******/

/****** PlugIn ******/
public void close()
{

}

public String getName()
{
return "Simple-Filter";
}

public void open() throws ResourceUnavailableException
{

}

public void reset()
{

}
/****** PlugIn ******/

/****** Controls ******/
public Object getControl(String controlType)
{
return null;
}

public Object[] getControls()
{
return null;
}
/****** Controls ******/

/****** Utility ******/
private Format matches(Format in, Format[] out)
{
if(in != null && out != null)
{
for(int i=0, cnt=out.length; i<cnt; i++)
{
if(in.matches(out[i]))
return out[i];
}
}

return null;
}
/****** Utility ******/
}

source