MediaPlayer setAudioStreamType - 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 setAudioStreamType method.

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
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 )
9
CodeRank
This code example shows how to use the following methods:setAudioStreamType
		 
		public AudioStreamer(Uri u) {
			uri = u;
			prepared = false;
			 
			mediaPlayer = new MediaPlayer();
			mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
			initMediaPlayer(); 
		} 
		 
		public void initMediaPlayer() { 
			try { 
				mediaPlayer.setDataSource(spark.getCloudLink());
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (IllegalStateException e) {
				e.printStackTrace();
			} catch (IOException e) {
7
CodeRank
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
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();   
	            }    
	        } 
6
CodeRank
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 )
7
CodeRank
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setOnCompletionListener, start
        notification.setLatestEventInfo(MyApp.getContext(), str, str, contentIntent);
        notificationManager.notify(R.drawable.ic_launcher, notification);
    } 
 
    public static void makeSound(Context context) {
        MediaPlayer mediaPlayer = new MediaPlayer();
        try { 
            mediaPlayer.setDataSource(context,
                    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } 
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
        try { 

6
CodeRank
This code example shows how to use the following methods:setAudioStreamType, setDataSource, setLooping, setOnErrorListener
    vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
    player = createPlayer();
  } 
 
  private MediaPlayer createPlayer() {
    MediaPlayer newPlayer = new MediaPlayer();
    try { 
      Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
      newPlayer.setOnErrorListener(playerErrorListener);
      newPlayer.setDataSource(context, ringtoneUri);
      newPlayer.setLooping(true);
      newPlayer.setAudioStreamType(AudioManager.STREAM_RING);
      return newPlayer;
    } catch (IOException e) {
      Log.e(TAG, "Failed to create player for incoming call ringer");
      return null; 
    } 
  } 
 
  public void start() { 
8
CodeRank
This code example shows how to use the following methods:setAudioStreamType, setOnBufferingUpdateListener, setOnCompletionListener, setOnErrorListener, setOnPreparedListener
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setLooping, start
                Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
 
        if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
            mPlayer.setAudioStreamType(silentModeStreams);
        } else { 
            mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
        } 
        try { 
            mPlayer.setDataSource(this, url);
            mPlayer.prepare();
            mPlayer.setLooping(true);
            mPlayer.start();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block 
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block 
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block 
8
CodeRank

Related MediaPlayer setAudioStreamType Questions & Answers:

setAudioStreamType Method Overview
Sets the audio stream type for this MediaPlayer.
See Code Examples for other Android MediaPlayer Methods: