These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaPlayer setDataSource method.
// Generate a random number, sends it to the ping test player. @Suppress @MediumTest public void testPing() throws Exception { mPlayer.setDataSource("test:invoke_mock_media_player.so?url=ping"); Parcel request = mPlayer.newRequest(); Parcel reply = Parcel.obtain(); int val = rnd.nextInt(); request.writeInt(val); mPlayer.invoke(request, reply); assertEquals(val, reply.readInt()); } }
public boolean isActive() { return false; } public boolean isRunning() { return player != null && player.isPlaying(); } public void start() { if (!isOpen()) { throw new IllegalStateException("Clip must be open"); } if (stream == null) { throw new IllegalStateException("Need an AudioInputStream to play"); } if (!isRunning()) { /* * This is ugly, but there is no way around it: The javax.sound API
protected long getDuration(String file) { long duration = -2; if (!isPlaying & !isStreaming(file)) { try { mPlayer = new MediaPlayer(); mPlayer.setDataSource("/sdcard/" + file); mPlayer.prepare(); duration = mPlayer.getDuration(); mPlayer.release(); } catch (Exception e) { e.printStackTrace(); return(-3); } } else if (isPlaying & !isStreaming(file)) { duration = mPlayer.getDuration(); } else if (isPlaying & isStreaming(file)) { try { duration = mPlayer.getDuration(); } catch (Exception e) { e.printStackTrace(); return(-4); } }else { return -1; }
private int state; public PGPolyphonicVoice( AssetFileDescriptor afd ) throws IOException { state = INVALID; mp = new MediaPlayer(); mp.setDataSource( afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.prepare(); } public void play() throws IOException { invokePlay( false ); } private void invokePlay( Boolean loop ) { Boolean playing = ( mp.isLooping() || mp.isPlaying() ); if ( playing )
void loadSound(String fileName, boolean stream){ try { if(stream){ if(player!=null) unloadSound(); player = new MediaPlayer(); player.setDataSource(fileName); player.prepare(); }else{ if(soundID!=-1) unloadSound(); soundID = pool.load(fileName, 1); } setVolume(volume); bIsLoaded = true; this.fileName = fileName; this.stream = stream; } catch (Exception e) { Log.e("OF","couldn't load " + fileName,e); } }
protected long getDuration(String file) { long duration = -2; if (!isPlaying & !isStreaming(file)) { try { mPlayer = new MediaPlayer(); mPlayer.setDataSource("/sdcard/" + file); mPlayer.prepare(); duration = mPlayer.getDuration(); mPlayer.release(); } catch (Exception e) { e.printStackTrace(); return(-3); } } else if (isPlaying & !isStreaming(file)) { duration = mPlayer.getDuration(); } else if (isPlaying & isStreaming(file)) { try { duration = mPlayer.getDuration(); } catch (Exception e) { e.printStackTrace(); return(-4); } }else { return -1; }
} protected void startPlaying(String file) { if (isPlaying==false) { try { mPlayer = new MediaPlayer(); isPlaying=true; Log.d("Audio startPlaying", "audio: " + file); if (isStreaming(file)) { Log.d("AudioStartPlaying", "Streaming"); // Streaming prepare async mPlayer.setDataSource(file); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.prepareAsync(); } else { Log.d("AudioStartPlaying", "File"); // Not streaming prepare synchronous, abstract base directory mPlayer.setDataSource("/sdcard/" + file); mPlayer.prepare();
mediaPlayer = new MediaPlayer(); isPaused = false; } public void play() { if (!mediaPlayer.isPlaying() && currentTrack != null) { try { if (!isPaused) { mediaPlayer.reset(); mediaPlayer.setDataSource(currentTrack); mediaPlayer.prepare(); isPaused = false; } mediaPlayer.start(); } catch (Exception e) { //ignore } } }
public void setListener(RecognizerApiListener listener) { this.mListener = listener; } public static void play(Activity activity, String file, PlaybackExceptionHandler handler) { MediaPlayer mediaPlayer = new MediaPlayer(); try { mediaPlayer.setDataSource(file); mediaPlayer.prepare(); mediaPlayer.start(); } catch (Exception e) { handler.playbackFailed(file); } } private AACEncoder encoder = new AACEncoder(); private long speechStarted = 0; private SpeechRecognizer sr; private ProgressDialog speakPd;
e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if(!player.isPlaying()) { player.start(); } } //Í£Ö¹ÄÖÁå public void stopMusic() { if (player != null) { player.stop(); try { // ÔÚµ÷ÓÃstopºóÈç¹ûÐèÒªÔÙ´Îͨ¹ýstart½øÐв¥·Å,ÐèҪ֮ǰµ÷ÓÃprepareº¯Êý player.prepare(); } catch (IOException ex) { ex.printStackTrace(); } }
236: }
237: });
238:
239: /**
240: * Button Click event for Play list click event