Playing an audio file on JButton press? - java

I've looked on Google for a while, searching how to play audio files, and most of the sources I found were with using java.applet.*, but I am trying to look for a way I can put it inside my actionPerformed() method.
public void actionPerformed(ActionEvent event) {
if(event.getActionCommand().equals("Play")){
//Short Audio File Playing Here
}
}

See the JavaSound info. page for the "Playing a Clip" section.

You may learn and use javax.sound API. Have a look at tutorial - Playing Back Audio.

Related

Java jlayer on RasberryPi

I am making a music player for rasberry pi. There is a hifiberry module connected to it. I am using a jlayer library for playing music. When i run the code on my PC (Ubuntu) it works fine, but when i try to run it on the rasberry, i dont get any error, but there is no sound playing. I tried reinstalling java. It does not work even without the module.
I am using this piece of code:
public class Main {
public static void main(String[] args) {
AdvancedPlayer player = new AdvancedPlayer(new FileInputStream(args[0]));
player.play();
}
}
Is there any solution for this? or can u suggest any library that could work, which supports mp3 files?
Somehow the audio was streaming to bad output, and i could not find a way to change the output port, so i used a mp3spi library, which i managed to get working.

libGDX - If I play a Sound, my Android-Phone stutters/have a micro lag

I'm new in libGDX and if I play a Sound, I have a micro stutter/lag.
My File has the ".wav" extension. - I already tried:
change the file-extensions
make the file-duration longer
I appreciate your help! :))
have a nice day
Recommend setting up an asset manager that loads the sound once before it is needed. This will allow for reuse and encapsulating the process of loading assets for all or parts of an application. Recommend strongly against recreating (reloading) the sound each time. Wave or ogg both work well. Some articles / posts recommend changing the size.
Create object or decode Sound file at once inside create() or in show() method and play that sound whenever you required.
private Sound hit;
#Override
public void create() {
hit = Gdx.audio.newSound(Gdx.files.internal("sfx_hit.wav"));
}
public void playSound(){
hit.play(0.5f);
}
#Override
public void dispose() {
hit.dispose(); // <- only dispose when you're no using further
}
Possible reason : Decoding a compressed file takes times so avoid to decode file each time when you want to play sound and Sample rate of your clip should be lower for fast processing.

Android Radio App that streams my mp3 from a dropbox server

I have a dropbox media server that has a collection of mp3 files that I want to stream onto an android application.
I know that using the "MediaPlayer" is the best way to go in the API.
How my main concern is how do I automate the process, where music is being played one after another? As if it was like an internet radio app?
Could someone please point me in the correct location for guides or display example code would be great thank you in advance.
Place the music files names in an arraylist (e.g songs) then implement onCompletionListener then set it to your media player. Inside the listener restart the media player to play the next item.
myMediaPlayer.setOnCompletionListener(this);
public void onCompletion(MediaPlayer arg0) {
arg0.release();
if (counter < songs.size()) {
counter++;
arg0 = MediaPlayer.create(getApplicationContext(), songs.get(counter);
arg0.setOnCompletionListener(this);
arg0.start();
}
}
If the server gives apps audio files;put the files in a queue and play them using mediaplayer or another audio player.
Get first song from server and start playing it, meanwhile continue downloading other songs one by one.

Is possible record only audio or only video with vlcj?

I'm newbie using vlcj and would like to know what options could be used to record audio only. In another situation, record only video.
I'm recording audio and video together, using the options below, but the project requires providing options to record audio or video regardless.
String[] options = {
":sout=#transcode{vcodec=mp1v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{mux=mpeg1,dst=" + fileName + "},dst=display}", ":input-slave=dshow://hw:0,0" };
I searched in google and also in stackoverflow, but have not found a solution for this specific case.
I appreciate any help possible.
Tks,
acsnrj
You can specify "dummy" for the video or audio codec.
This vlcj example transcodes only audio:
https://github.com/caprica/vlcj/blob/vlcj-2.4.1/src/test/java/uk/co/caprica/vlcj/test/rip/RipAudioTest.java
The relevant code from that example is:
mediaPlayer.playMedia(args[0], "sout=#transcode{acodec=mp3,channels=2,ab=192,samplerate=44100,vcodec=dummy}:standard{dst=" + args[1] + ",mux=raw,access=file}");
you can add "--no-video" option to playMedia function to avoid processing video.

YouTubeEmbededPlayer GWT HowTo stop videos?

I am trying to use the youtube video gwt api.
The youtube-player works but how can I stop videos? I didnt find a command for that...
I created my player following:
protected YouTubeEmbeddedPlayer _youTubeEmbeddedPlayer;
_youTubeEmbeddedPlayer = new YouTubeEmbeddedPlayer(youTubeVideoID);
That´s the YouTube Player:
https://code.google.com/p/gwt-youtube-api/wiki/EmbededPlayer
By using YouTubePlayerWrapper.
You can stop video by calling the method
youTubePlayerWrapper.stopVideo();
This answer may not resolve the problem mentioned with the same library. In fact I tried multiple different library with every library having some issues. So end up creating my own wrapper. I have made it public check it if you can use it https://github.com/pandurangpatil/gwt-youtube

Categories

Resources