Java Examples for javazoom.jl.player.advanced.AdvancedPlayer

The following java examples will help you to understand the usage of javazoom.jl.player.advanced.AdvancedPlayer. These source code samples are taken from different open source projects.

Example 1
Project: jukefox-master  File: PreparePlayerThread.java View source code
@Override
public void run() {
    FileInputStream fis;
    try {
        fis = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fis);
        player = new AdvancedPlayer(bis);
    //				System.out.println("Created player " + player.toString());
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (JavaLayerException e) {
        throw new RuntimeException(e);
    }
}
Example 2
Project: unifrog-master  File: unisound.java View source code
public void play(String sFile, boolean bLoop) {
    file = sFile;
    looped = bLoop;
    try {
        URL url = unifrog.class.getResource(file);
        mp3_in = new BufferedInputStream(url.openStream());
        mp3_player = new AdvancedPlayer(mp3_in);
        mp3_player.setPlayBackListener(pb);
        thread = new Thread(new unisound());
        thread.start();
        stopped = false;
    //(new Thread( new unisound())).start();
    } catch (MalformedURLException ex) {
    } catch (IOException e) {
    } catch (JavaLayerException e) {
    } catch (NullPointerException ex) {
    }
}
Example 3
Project: VA-Project-master  File: SoundPlayer.java View source code
public void play(Runnable onStart, Runnable onEnd) {
    try {
        this.onStart = onStart;
        this.onEnd = onEnd;
        this.player = new AdvancedPlayer(new URL(this.filePath).openStream(), FactoryRegistry.systemRegistry().createAudioDevice());
        this.player.setPlayBackListener(this);
        this.playerThread = new Thread(this);
        this.playerThread.start();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (JavaLayerException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 4
Project: Lyst-master  File: Mp3Player.java View source code
@Override
public void play(final Song song, final int playFrom) throws SongPlayException {
    try {
        forceStopped = false;
        forcePaused = false;
        player = new AdvancedPlayer(new BufferedInputStream(new FileInputStream(song.getFile())));
        PlaybackListener listener = new PlaybackListener() {

            @Override
            public void playbackStarted(PlaybackEvent arg0) {
                playbackListener.getNotification(new PlayEvent(PlayEvent.EventType.PLAY_STARTED));
            }

            @Override
            public void playbackFinished(PlaybackEvent event) {
                PlayEvent playEvent = new PlayEvent(forceStopped ? PlayEvent.EventType.SONG_STOPPED : forcePaused ? PlayEvent.EventType.SONG_PAUSED : PlayEvent.EventType.SONG_ENDED);
                playEvent.setFrame(playFrom + (44 * event.getFrame() / 1000));
                playbackListener.getNotification(playEvent);
            }
        };
        player.setPlayBackListener(listener);
        player.play(playFrom, Integer.MAX_VALUE);
    } catch (Exception e) {
        logger.error("Song file not found", e);
        throw new SongPlayException();
    }
}
Example 5
Project: eert-master  File: EMusicPlayerMP3.java View source code
public void play() {
    try {
        InputStream is = new BufferedInputStream(Music.class.getResourceAsStream(this.name));
        FactoryRegistry r = FactoryRegistry.systemRegistry();
        device = r.createAudioDevice();
        player = new AdvancedPlayer(is, device);
        player.setPlayBackListener(new PlaybackListener() {

            @Override
            public void playbackStarted(PlaybackEvent playbackEvent) {
                //vmech().onMessage("Playback started..");
                System.out.println("Playback started..");
            //		   thread.resume();
            }

            public void playbackFinished(PlaybackEvent playbackEvent) {
                //vmech().onMessage("Playback finished..");
                System.out.println("Playback finished..");
            }
        });
        thread = new Thread(this);
        thread.start();
    } catch (JavaLayerException e) {
        e.printStackTrace();
    }
}
Example 6
Project: MP3ToolKit-master  File: MP3Player.java View source code
/**
	 * creates the new player
	 * 
	 * @throws AudioPlayerException
	 *             thrown if advanced player couldn't read inputstream
	 */
private void createPlayer() throws AudioPlayerException {
    try {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path));
        this.player = new AdvancedPlayer(bis);
    } catch (IOExceptionJavaLayerException |  e) {
        logger.log(Level.SEVERE, "Error while init audio player:\n" + LogUtil.getStackTrace(e), e);
        throw new AudioPlayerException("Error while init file: " + this.path);
    }
}
Example 7
Project: interactivespaces-master  File: JLayerAudioTrackPlayer.java View source code
@Override
public synchronized void start(final FilePlayableAudioTrack track) {
    if (playing.get()) {
        throw new SimpleInteractiveSpacesException((String.format("Cannot start playing audio file %s: Already playing a track", track.getFile().getAbsolutePath())));
    }
    File file = track.getFile();
    if (!file.exists()) {
        throw new SimpleInteractiveSpacesException((String.format("Cannot find audio file %s", file.getAbsolutePath())));
    }
    try {
        final FileInputStream trackStream = new FileInputStream(file);
        player = new AdvancedPlayer(trackStream);
        player.setPlayBackListener(new PlaybackListener() {

            @Override
            public void playbackFinished(PlaybackEvent event) {
                playing.set(false);
                notifyTrackStop(track);
            }

            @Override
            public void playbackStarted(PlaybackEvent event) {
                playing.set(true);
                notifyTrackStart(track);
            }
        });
        // The JLayer play() method runs entirely in the calling thread,
        // which means it blocks until the song is complete. So run in its own
        // thread.
        executorService.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    player.play();
                } catch (JavaLayerException e) {
                    log.error("JLayer player failed during MP3 playback", e);
                } finally {
                    Closeables.closeQuietly(trackStream);
                }
            }
        });
    } catch (Exception e) {
        throw new InteractiveSpacesException((String.format("Cannot create audio player for file %s", file.getAbsolutePath())), e);
    }
}
Example 8
Project: MineTunes-master  File: ThreadMusicPlayer.java View source code
@Override
public void run() {
    try {
        GuiDevTools.debugLog("Starting " + this);
        while (!kill) {
            if (queued && playingMP3 != null) {
                GuiDevTools.debugLog("Queued: " + playingMP3.file.getAbsolutePath());
                if (player != null)
                    resetPlayer();
                player = new AdvancedPlayer(new FileInputStream(playingMP3.file));
                player.setPlayBackListener(listener);
                queued = false;
                GuiDevTools.debugLog("Player (Re)loaded");
            }
            boolean played = false;
            if (player != null && player.getAudioDevice() != null) {
                if (pauseFrames == 0) {
                    GuiDevTools.debugLog("Playing File");
                    player.play();
                    playing = true;
                } else if (!paused) {
                    GuiDevTools.debugLog("Was paused, restarting at " + pauseFrames);
                    int startFrame = pauseFrames;
                    pauseFrames = 0;
                    player.play(startFrame, Integer.MAX_VALUE);
                    playing = true;
                }
                played = true;
            }
            if (played && !paused && !queued) {
                GuiDevTools.debugLog("Song done, next...");
                next();
            }
        }
    } catch (Exception e) {
        GuiDevTools.logThrowable(e);
    }
}
Example 9
Project: triple-master  File: ClipPlayer.java View source code
private void playClip(final String clipName, final PlayerID playerId) {
    if (beSilent || isMuted(clipName)) {
        return;
    }
    // run in a new thread, so that we do not delay the game
    String folder = clipName;
    if (playerId != null) {
        folder += "_" + playerId.getName();
    }
    final URI clip = loadClip(folder).orElse(loadClip(clipName).orElse(null));
    if (clip != null) {
        (new Thread(() -> {
            try {
                Optional<InputStream> inputStream = UrlStreams.openStream(clip.toURL());
                if (inputStream.isPresent()) {
                    final AudioDevice audioDevice = FactoryRegistry.systemRegistry().createAudioDevice();
                    new AdvancedPlayer(inputStream.get(), audioDevice).play();
                }
            } catch (Exception e) {
                ClientLogger.logError("Failed to play: " + clip, e);
            }
        })).start();
    }
}