MediaPlayer setDataSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaPlayer setDataSource method.

This code example shows how to use the following methods: setDataSource, invoke, newRequest
 
    // 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());
   } 
} 
Full Snippet Info
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: isPlaying, prepare, setAudioStreamType, setDataSource, start
    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 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getDuration, prepare, release, setDataSource
 
	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; } 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: prepare, setAudioStreamType, setDataSource
	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 )
Full Snippet Info
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: prepare, setDataSource, setVolume
	 
	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);
		}  
	} 

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getDuration, prepare, release, setDataSource
	 
	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; } 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: prepare, prepareAsync, setAudioStreamType, setDataSource, setOnPreparedListener
	}	 
	 
	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();

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: isPlaying, prepare, reset, setDataSource, start
		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 
			}    		 
    	} 
    } 
     
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: prepare, setDataSource, start
    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;
Full Snippet Info
10
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: isPlaying, prepare, setAudioStreamType, setDataSource, setLooping
				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();   
	            }    
	        } 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related MediaPlayer setDataSource Questions & Answers:

Other MediaPlayer setDataSource Examples

236:				}
237:			});
238:	
239:			/**
240:			 * Button Click event for Play list click event

Read More

setDataSource Method Overview
Sets the data source (file-path or http/rtsp URL) to use.
See Code Examples for other Android MediaPlayer Methods: