Tag Archive for mp3

Javascript – Play Sound (IE & FF)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Reproducir sonido - By Nicolás Pardo 2007</title>

<script>
function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/*Namespaces*/
var Media = document.Media || {};
// funciones para cookies

Media.PlaySound = {
MSIE: navigator.userAgent.indexOf("MSIE"),
NETS: navigator.userAgent.indexOf("Netscape"),
OPER: navigator.userAgent.indexOf("Opera"),
cookieName:  "cookie_sound_active",
imgOn: "images/ico_on.gif",
imgOff: "images/ico_off.gif",
Sound: "_sonido.wav",
WriteCookie: function( name, value ){
var expdate=new Date();
expdate.setTime(expdate.getTime()+10*365*24*60*60*1000);
document.cookie = name + "=" + escape (value) + "; expires=" + expdate.toGMTString();
},
ReadCookie: function( name ){
var namearg = name + "=";
var nlen = namearg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + nlen;
if (document.cookie.substring(i, j) == namearg) {
var endpos = document.cookie.indexOf (";", j);
if (endpos == -1) endpos = document.cookie.length;
return unescape(document.cookie.substring(j, endpos));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
},
OnOffSound: function( img ){
newValue = Media.PlaySound.ReadCookie( Media.PlaySound.cookieName ) == 1 || Media.PlaySound.ReadCookie( Media.PlaySound.cookieName ) == null  ? 0 : 1;
img.src = newValue == 1 ? Media.PlaySound.imgOn : Media.PlaySound.imgOff;
Media.PlaySound.WriteCookie( Media.PlaySound.cookieName, newValue );
},
SetMediaIE: function(){
if((Media.PlaySound.MSIE>-1) || (Media.PlaySoundOPER>-1)) {
document.write('<bgsound loop="0" name="MediaMyMediaObj" id="MediaMyMediaObj" >');
}
},
PlayNow: function(){
if( Media.PlaySound.ReadCookie( Media.PlaySound.cookieName ) == 1 || Media.PlaySound.ReadCookie( Media.PlaySound.cookieName ) == null ){
obj = MM_findObj("MediaMyMedia");
if((Media.PlaySound.MSIE>-1) || (Media.PlaySoundOPER>-1)) {
obj = MM_findObj("MediaMyMediaObj");
obj.src = Media.PlaySound.Sound;
} else {
obj = MM_findObj("MediaMyMediaDiv");
obj.innerHTML = '<embed  src="'+Media.PlaySound.Sound+'" hidden="true" volume="200" loop="0" type="audio/midi" >';
}
}
}
}

Media.PlaySound.SetMediaIE();
</script>
</head>
<body>
<a href="#"><img src="images/ico_on.gif" onclick="Media.PlaySound.OnOffSound(this)" border="0" /></a>
<br />

<div name="MediaMyMediaDiv" id="MediaMyMediaDiv" style="margin:0; width:0; height:0;"></div>
<input type="button" value="dame" onclick="Media.PlaySound.PlayNow()" />
</body>
</html>

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

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

Bash – avi2mpg

ffmpeg -i video.avi -target vcd video.mpg

source

mp3 desde gmail

<center><iframe style="border: 1px solid rgb(170, 170, 170); width: 500px; height: 25px;" id="musicPlayer" src="http://mail.google.com/mail/html/audio.swf?audioUrl=URL DEL ARCHIVO MP3">    </iframe></center>

source

gmail/google mp3 flash player

<center><iframe style="border: 1px solid rgb(170, 170, 170); width: 500px; height: 25px;" id="musicPlayer" src="http://mail.google.com/mail/html/audio.swf?audioUrl=URLMP3FILE MP3">    </iframe></center>

source

Easily play mp3 files directly on your website or blog using del.icio.us PlayTagger

<script type="text/javascript" src="http://del.icio.us/js/playtagger"></script>

source

Embedded Odeo player

<embed src= "http://www.odeo.com/flash/audio_player_standard_gray.swf" quality="high" width="300" height="52" allowScriptAccess="always" wmode="transparent"  type="application/x-shockwave-flash" flashvars= "valid_sample_rate=true&external_url=[MP3 file address]" pluginspage="http://www.macromedia.com/go/getflashplayer" /></embed>

source