Package javax.microedition.media

Examples of javax.microedition.media.Player


        {
          if(this.getBarcodeScanner() != null) {
                BarcodeScanner bcScanner = this.getBarcodeScanner();
                bcScanner.stopScan();          
          }
          Player cPlayer = this.getCameraPlayer();
          if(cPlayer != null && (cPlayer.getState() != Player.CLOSED)) {
            cPlayer.close();
          }
            UiApplication.getUiApplication().popScreen(ScannerScreen.this);
        }
        catch (MediaException me)
        {
View Full Code Here


    }

    private void playSoundFile(String file) {
        try {
            InputStream is = getClass().getResourceAsStream(file);
            Player p = Manager.createPlayer(is, "audio/x-wav");
            p.start();
        } catch (Exception e) {
            //#ifdef debug
            Alert a = new Alert("Exception", e.toString(), null, AlertType.INFO);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a);
View Full Code Here

        _mediaActions = null;
        _screen = null;
        _volumeController = null;
        _playlist = null;

        final Player player = _player;
        _player = null;
        if (player != null) {
            try {
                player.stop();
            } catch (final Exception e) {
            }
            try {
                player.close();
            } catch (final Exception e) {
            }
        }
    }
View Full Code Here

     * @return true If track change operation was successful, false otherwise
     * @throws MediaActionException
     *             If an error occurs performing this action
     */
    public boolean doChangeTrack() throws MediaActionException {
        final Player player = _handler.getPlayer();

        if (MediaPlayerDemo.isPlaying(player)) {
            doStop();
        }

View Full Code Here

        final int size = _handler.getTotalTracks();
        if (index < 0 || index >= size) {
            return false;
        }

        Player player = _handler.getPlayer();
        if (MediaPlayerDemo.isPlaying(player)) {
            forcePlay = true;
        }

        if (player != null) {
View Full Code Here

     * @return true If the pause operation was successful, false otherwise
     * @throws MediaActionException
     *             If an error occurs performing this action
     */
    public boolean doPause() throws MediaActionException {
        final Player player = _handler.getPlayer();

        if (player == null || player.getState() != Player.STARTED) {
            // Not playing, nothing to do
            return false;
        }

        if (player != null) {
            try {
                player.stop();
            } catch (final Exception e) {
                throw new MediaActionException("Unable to unpause player: " + e);
            }
        }

View Full Code Here

     * @return true If the play operation was successful, false otherwise
     * @throws MediaActionException
     *             If an error occurs performing this action
     */
    public boolean doPlay() throws MediaActionException {
        Player player = _handler.getPlayer();

        if (player != null) {
            if (player.getState() == Player.STARTED) {
                // Already playing, nothing to do
                return false;
            }
        }

        if (player == null) {
            final MediaPlayerDemoScreen screen = _handler.getScreen();
            if (screen == null) {
                return false; // MediaPlayerDemo has closed
            }

            final PlaylistEntry entry = screen.getCurrentPlaylistEntry();
            if (entry == null) {
                return false; // No entry to play
            }

            final String url = entry.getURL();
            try {
                player = Manager.createPlayer(url);
            } catch (final Exception e) {
                throw new MediaActionException("unable to load media from "
                        + url + ": " + e);
            }
            _handler.setPlayer(player);
            player.addPlayerListener(_handler);

            try {
                player.realize();
            } catch (final Exception e) {
                throw new MediaActionException("unable to fetch media: " + e);
            }

            // Cause playback to begin as soon as possible once start()
            // is called on the Player.
            final StreamingBufferControl sbc =
                    (StreamingBufferControl) player
                            .getControl("net.rim.device.api.media.control.StreamingBufferControl");
            sbc.setBufferTime(0);

            Control control = player.getControl("VolumeControl");
            if (control instanceof VolumeControl) {
                final VolumeControl volumeControl = (VolumeControl) control;
                _handler.setVolumeController(volumeControl);

                // Unmute the application on the assumption that if the user
                // asks to
                // play a track they actually want to hear it.
                try {
                    doMute(false);
                } catch (final Exception e) {
                    _handler.setVolumeController(null);
                    control = null;
                }

                // Set the volume to match the last-selected level
                try {
                    _handler.changeVolume(_handler.getVolume());
                } catch (final Exception e) {
                    _handler.setVolumeController(null);
                    control = null;
                }
            }
        }

        if (player != null) {
            try {
                player.start();
            } catch (final Exception e) {
                throw new MediaActionException("unable start player: " + e);
            }
        }
        return true;
View Full Code Here

     * @return true If the track operation was successful, false otherwise
     * @throws MediaActionException
     *             If an error occurs performing this action
     */
    public boolean doPrevTrack() throws MediaActionException {
        final Player player = _handler.getPlayer();

        if (MediaPlayerDemo.isPlaying(player)) {
            final long timeInMicroSeconds = player.getMediaTime();

            // If more that 2 seconds has elapsed, then go back to the beginning
            if (timeInMicroSeconds > 2000000L) {
                try {
                    player.setMediaTime(0);
                    return true;
                } catch (final Exception e) {
                    throw new MediaActionException(
                            "unable to go back to beginning: " + e);
                }
View Full Code Here

     * @return true If the stop operation was successful, false otherwise
     * @throws MediaActionException
     *             If an error occurs performing this action
     */
    public boolean doStop() throws MediaActionException {
        final Player player = _handler.getPlayer();
        if (player == null) {
            // Already stopped, nothing to do
            return false;
        }

        _handler.setPlayer(null);
        _handler.setVolumeController(null);

        try {
            player.removePlayerListener(_handler);
        } catch (final Exception e) {
        }

        try {
            player.close();
        } catch (final Exception e) {
            throw new MediaActionException("closing Player failed: " + e);
        }

        return true;
View Full Code Here

TOP

Related Classes of javax.microedition.media.Player

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.