javax.microedition.media.Player Java Examples
The following examples show how to use
javax.microedition.media.Player.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public static MMAPIPlayer createPlayer(InputStream stream, String mimeType, Runnable onCompletion) throws IOException { try { Player p = Manager.createPlayer(stream, mimeType); p.realize(); MMAPIPlayer m = new MMAPIPlayer(p); m.bindPlayerCleanupOnComplete(p, stream, onCompletion); return m; } catch (MediaException ex) { if("audio/mpeg".equals(mimeType)) { return createPlayer(stream, "audio/mp3", onCompletion); } ex.printStackTrace(); throw new IOException(ex.toString()); } }
Example #2
Source File: BarCodeScanner.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void startScan() { player = (Player) media.getVideoComponent().getClientProperty("nativePlayer"); MultimediaManager multimediaManager = buildMultimediaManager(); if (player != null) { multimediaManager.setZoom(player); multimediaManager.setExposure(player); multimediaManager.setFlash(player); } media.play(); snapshotThread = new SnapshotThread(this); new Thread(snapshotThread).start(); if (Display.getInstance().isEdt()) { cameraForm.show(); } else { // Now show the dialog in EDT Display.getInstance().callSerially(new Runnable() { public void run() { cameraForm.show(); } }); } }
Example #3
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void playerUpdate(Player player, String event, Object eventData) { if(deleted) { return; } if(PlayerListener.ERROR.equals(event)) { lastTime = (int)(nativePlayer.getMediaTime() / 1000); cleanup(); } if(PlayerListener.END_OF_MEDIA.equals(event)) { lastTime = (int)(nativePlayer.getMediaTime() / 1000); if(disposeOnComplete){ cleanup(); if(sourceStream != null) { try { sourceStream.close(); } catch(Throwable t) {} } } if(onComplete != null) { onComplete.run(); } } }
Example #4
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void playerUpdate(Player player, String event, Object eventData) { if (deleted) { return; } if (PlayerListener.ERROR.equals(event)) { lastTime = (int) (nativePlayer.getMediaTime() / 1000); cleanup(); } if (PlayerListener.END_OF_MEDIA.equals(event)) { lastTime = (int) (nativePlayer.getMediaTime() / 1000); if (disposeOnComplete) { cleanup(); if (sourceStream != null) { try { sourceStream.close(); } catch (Throwable t) { } } } if (onComplete != null) { onComplete.run(); } } }
Example #5
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public static MMAPIPlayer createPlayer(InputStream stream, String mimeType, Runnable onCompletion) throws IOException { try { Player p = Manager.createPlayer(stream, mimeType); p.realize(); MMAPIPlayer m = new MMAPIPlayer(p); m.bindPlayerCleanupOnComplete(p, stream, onCompletion); return m; } catch (MediaException ex) { if ("audio/mpeg".equals(mimeType)) { return createPlayer(stream, "audio/mp3", onCompletion); } ex.printStackTrace(); throw new IOException(ex.toString()); } }
Example #6
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
public void addPlayer( Player player ) throws MediaException { checkIfPlayerIsNull( player ); checkPlayerStates( player ); if( _players.containsKey( player ) ) { throw new IllegalArgumentException( "Cannot add a Player to a Module if either the Player or one " + "of its MIDI channels is already part of the Module" ); } doAddPlayer( player ); _players.put( player, new PlayerConnectionInfo() ); }
Example #7
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
private void checkPlayerStates( Player playerToAddOrRemove ) { if( !isPlayerStateAcceptable( playerToAddOrRemove ) ) { throw new IllegalStateException( "JSR-234 Module: Cannot add/remove a Player in PREFETCHED or STARTED state" ); } Enumeration e = _players.keys(); while( e.hasMoreElements() ) { if( !isPlayerStateAcceptable( ( Player )e.nextElement() ) ) { throw new IllegalStateException( "JSR-234 Module: Cannot add/remove a Player when connected " + "with any other Player in PREFETCHED or STARTED state" ); } } }
Example #8
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public void addMIDIChannel( Player player, int channel ) throws MediaException { checkChannelNumberRange( channel ); checkIfPlayerIsNull( player ); checkIfPlayerIsMIDI( player ); checkPlayerStates( player ); PlayerConnectionInfo conn = ( PlayerConnectionInfo )_players.get( player ); if( conn != null ) { if( !conn.canAddMIDIChannel( channel ) ) { throw new IllegalArgumentException( "Cannot add a MIDI channel to a Module if either the channel or the whole " + "Player is already part of the Module" ); } } doAddMIDIChannel( player, channel ); if( conn != null ) { conn.addMIDIChannel( channel ); } else { conn = new PlayerConnectionInfo( channel ); _players.put( player, conn ); } }
Example #9
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void bindPlayerCleanupOnComplete(final Player p, final InputStream i, final Runnable onComplete) { if(volume > -1) { VolumeControl v = (VolumeControl) p.getControl("VolumeControl"); if(v != null) { v.setLevel(volume); } } sourceStream = i; this.onComplete = onComplete; p.addPlayerListener(this); }
Example #10
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
private static void checkIfPlayerIsMIDI( Player p ) { if( !isPlayerMIDI( p ) ) { throw new IllegalArgumentException( "JSR-234 Module: Cannot add/remove a MIDI channel of a " + "Player that is not a MIDI Player" ); } }
Example #11
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
private static void checkIfPlayerIsNull( Player player ) { if( player == null ) { throw new IllegalArgumentException( "JSR-234 Module: Cannot add/remove a null player" ); } }
Example #12
Source File: Clip.java From J2ME-Loader with Apache License 2.0 | 5 votes |
protected Player getPlayer() { Player player = null; try { if (data != null) { player = Manager.createPlayer(new ByteArrayInputStream(data), contentType); } else { player = Manager.createPlayer(str); } } catch (IOException e) { e.printStackTrace(); } return player; }
Example #13
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public void removeMIDIChannel( Player player, int channel ) { checkChannelNumberRange( channel ); checkIfPlayerIsNull( player ); checkIfPlayerIsMIDI( player ); checkPlayerStates( player ); PlayerConnectionInfo conn = ( PlayerConnectionInfo )_players.get( player ); if( conn == null ) { throw new IllegalArgumentException( "Cannot remove a MIDI channel that is not a part of the Module" ); } if( !conn.canRemoveMIDIChannel( channel ) ) { throw new IllegalArgumentException( "Cannot remove a MIDI channel that is not a part of the Module" ); } doRemoveMIDIChannel( player, channel ); conn.removeMIDIChannel( channel ); if( conn.allChannelsRemoved() ) { _players.remove( player ); } }
Example #14
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public void removePlayer( Player player ) { checkIfPlayerIsNull( player ); checkPlayerStates( player ); if( !isAddedWholly( player ) ) { throw new IllegalArgumentException( "Cannot remove the Player because it is not a part of the Module" ); } doRemovePlayer( player ); _players.remove( player ); }
Example #15
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
protected boolean isAddedWholly( Player p ) { boolean added = false; PlayerConnectionInfo conn = ( PlayerConnectionInfo )_players.get( p ); if( conn != null ) { added = conn.isAddedWholly(); } return added; }
Example #16
Source File: MIDPVideoRenderer.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
/**************************************************************** * VideoControl implementation ****************************************************************/ MIDPVideoRenderer(Player p) { if (p instanceof BasicPlayer) { this.player = (BasicPlayer)p; locatorString = player.getLocator(); } else { System.err.println("video renderer can't work with Players of this class: " + p.toString()); } }
Example #17
Source File: PlayerPool.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
/** * PlayerListener interface's method. */ public void playerUpdate(Player player, String event, Object eventData) { if (event.equals(PlayerListener.VOLUME_CHANGED)) { // Gauge is adjusted actualVolume = (int) (((float) globalVolume / 100) * (float) midletVolume); } else if (event.equals("com.nokia.external.volume.event")) { // External volumes keys are pressed globalVolume = Integer.parseInt(eventData.toString()); actualVolume = (int) (((float) globalVolume / 100) * (float) midletVolume); } midlet.actualVolume = actualVolume; midlet.globalVolume = globalVolume; midlet.midletVolume = midletVolume; midlet.eventString = event; midlet.updateVolume(); }
Example #18
Source File: PlayerPool.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
/** * Set volume level to existing players. */ private void updateVolumeLevel() { int size = players.size(); for (int i = 0; i < size; i++) { // Set the same volume level for all players Player player = (Player) players.elementAt(i); VolumeControl control = (VolumeControl) player.getControl("VolumeControl"); actualVolume = (int) (((float) globalVolume / 100) * (float) midletVolume); control.setLevel(midletVolume); } }
Example #19
Source File: PlayerPool.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
/** * Set current stop-time to existing players. */ private void updateStopTime() { int size = players.size(); for (int i = 0; i < size; i++) { // Set the same stop time for all players Player player = (Player) players.elementAt(i); StopTimeControl control = (StopTimeControl) player.getControl("StopTimeControl"); control.setStopTime(stopTime); } }
Example #20
Source File: PlayerPool.java From pluotsorbet with GNU General Public License v2.0 | 5 votes |
public void closeAllPlayers() { if(players!= null && players.size()>0){ for (int i = 0; i < players.size(); i++) { try { Player player = (Player)players.elementAt(i); player.close(); } catch (Exception e) { e.printStackTrace(); } } players.removeAllElements(); } }
Example #21
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
MMAPIPlayer(Player p) { this.nativePlayer = p; if(volume > -1){ setVolume(volume); }else{ setVolume(100); } }
Example #22
Source File: Sound.java From J2ME-Loader with Apache License 2.0 | 5 votes |
public void play(int loop) { try { if (loop == 0) { loop = -1; } if (player.getState() == Player.STARTED) { player.stop(); } player.setLoopCount(loop); player.start(); postEvent(SOUND_PLAYING); } catch (MediaException e) { e.printStackTrace(); } }
Example #23
Source File: AudioClip.java From J2ME-Loader with Apache License 2.0 | 5 votes |
public void play(int loop, int volume) { try { if (loop == 0) { loop = -1; } if (player.getState() == Player.STARTED) { player.stop(); } player.setLoopCount(loop); player.start(); } catch (MediaException e) { e.printStackTrace(); } }
Example #24
Source File: BaseModule.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public void addPlayer(Player player) throws MediaException { if (player == null) { throw new IllegalArgumentException("Player is null."); } if (player.getState() == Player.CLOSED) { throw new IllegalStateException("Can't add Player while it's in CLOSED state."); } players.add(player); }
Example #25
Source File: BaseModule.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public void removePlayer(Player player) { if (player == null) { throw new IllegalArgumentException("Player is null."); } players.remove(player); }
Example #26
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private MMAPIPlayer(Player p) { this.nativePlayer = p; if (volume > -1) { setVolume(volume); } else { setVolume(100); } }
Example #27
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * @inheritDoc */ public static MMAPIPlayer createPlayer(String uri, Runnable onCompletion) throws IOException { try { Player p = Manager.createPlayer((String) uri); p.realize(); MMAPIPlayer m = new MMAPIPlayer(p); m.bindPlayerCleanupOnComplete(p, null, onCompletion); return m; } catch (MediaException ex) { ex.printStackTrace(); throw new IOException(ex.toString()); } }
Example #28
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void bindPlayerCleanupOnComplete(final Player p, final InputStream i, final Runnable onComplete) { if (volume > -1) { VolumeControl v = (VolumeControl) p.getControl("VolumeControl"); if (v != null) { v.setLevel(volume); } } sourceStream = i; this.onComplete = onComplete; p.addPlayerListener(this); }
Example #29
Source File: MMAPIPlayer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * @inheritDoc */ public static MMAPIPlayer createPlayer(String uri, Runnable onCompletion) throws IOException { try { Player p = Manager.createPlayer((String)uri); p.realize(); MMAPIPlayer m = new MMAPIPlayer(p); m.bindPlayerCleanupOnComplete(p, null, onCompletion); return m; } catch (MediaException ex) { ex.printStackTrace(); throw new IOException(ex.toString()); } }
Example #30
Source File: BasicDirectModule.java From pluotsorbet with GNU General Public License v2.0 | 4 votes |
private static boolean isPlayerMIDI( Player p ) { return p.getContentType().toLowerCase().indexOf( "midi" ) != -1; }