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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE

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: