當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaPlayer.setAudioStreamType方法代碼示例

本文整理匯總了Java中android.media.MediaPlayer.setAudioStreamType方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.setAudioStreamType方法的具體用法?Java MediaPlayer.setAudioStreamType怎麽用?Java MediaPlayer.setAudioStreamType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.MediaPlayer的用法示例。


在下文中一共展示了MediaPlayer.setAudioStreamType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: playVideo

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void playVideo(Integer Media) {
    doCleanUp();
    try {
        // Create a new media player and set the listeners
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.setDisplay(holder);
        mMediaPlayer.prepareAsync();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}
 
開發者ID:narenkukreja,項目名稱:quire,代碼行數:18,代碼來源:MediaPlayerActivity.java

示例2: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:22,代碼來源:BeepManager.java

示例3: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.qr_sacn);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:22,代碼來源:BeepManager.java

示例4: createPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer createPlayer() {
  try {
    MediaPlayer mediaPlayer = new MediaPlayer();
    Uri         ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
    mediaPlayer.setDataSource(context, ringtoneUri);
    mediaPlayer.setLooping(true);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);

    return mediaPlayer;
  } catch (IOException e) {
    Log.e(TAG, "Failed to create player for incoming call ringer");
    return null;
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:17,代碼來源:IncomingRinger.java

示例5: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mediaPlayer.setOnCompletionListener(this);
  mediaPlayer.setOnErrorListener(this);

  AssetFileDescriptor file = activity.getResources().openRawResourceFd(keepass2android.plugin.qr.R.raw.beep);
  try {
    mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    file.close();
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer = null;
  }
  return mediaPlayer;
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:19,代碼來源:BeepManager.java

示例6: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  try {
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
    try {
      mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    } finally {
      file.close();
    }
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setLooping(false);
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
    return mediaPlayer;
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer.release();
    return null;
  }
}
 
開發者ID:kkyflying,項目名稱:CodeScaner,代碼行數:22,代碼來源:BeepManager.java

示例7: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    // mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources()
                .openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(),
                    file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(0.10f, 0.10f);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:c3cashdesk,項目名稱:postixdroid,代碼行數:23,代碼來源:MainActivity.java

示例8: createPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer createPlayer() {
    try {
        MediaPlayer mediaPlayer = new MediaPlayer();
        Uri         ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

        mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
        mediaPlayer.setDataSource(context, ringtoneUri);
        mediaPlayer.setLooping(true);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);

        return mediaPlayer;
    } catch (IOException e) {
        Log.e(TAG, "Failed to create player for incoming call ringer");
        return null;
    }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:17,代碼來源:IncomingRinger.java

示例9: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
	MediaPlayer mediaPlayer = new MediaPlayer();
	mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
	mediaPlayer.setOnCompletionListener(this);
	mediaPlayer.setOnErrorListener(this);

	AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
	try {
		mediaPlayer.setDataSource(file.getFileDescriptor(),
				file.getStartOffset(), file.getLength());
		file.close();
		mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
		mediaPlayer.prepare();
	} catch (IOException ioe) {
		Log.w(TAG, ioe);
		mediaPlayer = null;
	}
	return mediaPlayer;
}
 
開發者ID:dufangyu1990,項目名稱:LeCatApp,代碼行數:20,代碼來源:BeepManager.java

示例10: playProgressTone

import android.media.MediaPlayer; //導入方法依賴的package包/類
public void playProgressTone() {
    mPlayer = new MediaPlayer();
    mPlayer.setAudioStreamType(AudioManager.STREAM_RING);
    int maxVolume = 100;
    final float volume = (float) (1 - (Math.log(maxVolume - 1) / Math.log(maxVolume)));
    mPlayer.setVolume(volume, volume);

    try {
        //mPlayer.setDataSource(mContext, Uri.parse("android.resource://" + mContext.getPackageName() + "/" + R.raw.phone_loud1));
        mPlayer.prepare();
    } catch (IOException e) {
        Log.e(LOG_TAG, "Could not setup media player for ringtone");
        mPlayer = null;
        return;
    }
    mPlayer.setLooping(true);
    mPlayer.start();
}
 
開發者ID:squareboat,項目名稱:Excuser,代碼行數:19,代碼來源:AudioPlayer.java

示例11: onCreate

import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //initializing button
    btn = findViewById(R.id.play);

    //initializing mediaPlayer object
    mediaPlayer = new MediaPlayer();

    //setting streaming type
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    //setting clickListener on button
    btn.setOnClickListener(pausePlay);

}
 
開發者ID:stoic1979,項目名稱:DroidStreamingDemo,代碼行數:19,代碼來源:MainActivity.java

示例12: initAudioPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void initAudioPlayer() throws IOException {
        audioPlay = new MediaPlayer();
//        audioPlay.setOnPreparedListener(prepareListener);
        audioPlay.setOnCompletionListener(endAudioListener);
        audioPlay.setAudioStreamType(AudioManager.STREAM_MUSIC);
        audioPlay.setDataSource(audioFilePath);
        audioPlay.prepare();
    }
 
開發者ID:gvsucis,項目名稱:mobile-app-dev-book,代碼行數:9,代碼來源:AudioActivity.java

示例13: AndroidMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
public AndroidMediaPlayer() {
    synchronized (mInitLock) {
        mInternalMediaPlayer = new MediaPlayer();
    }
    mInternalMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mInternalListenerAdapter = new AndroidMediaPlayerListenerHolder(this);
    attachInternalListeners();
}
 
開發者ID:bigjelly,項目名稱:ShaddockVideoPlayer,代碼行數:9,代碼來源:AndroidMediaPlayer.java

示例14: blastTheAlarm

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void blastTheAlarm(String mediaUrl) {
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);

    try {
        mMediaPlayer.setDataSource(mediaUrl);
    } catch (IOException e) {
        Log.e(TAG, String.format("Error playing media from URL: %s", mediaUrl));
    }

    setAlarmToMaxVolume();
    mMediaPlayer.prepareAsync();
    mMediaPlayer.setOnPreparedListener(mp -> mMediaPlayer.start());
}
 
開發者ID:KevinLiddle,項目名稱:crockpod,代碼行數:15,代碼來源:AlarmRingingActivity.java

示例15: toggle

import android.media.MediaPlayer; //導入方法依賴的package包/類
public boolean toggle(int id, VoiceMessage audio) throws PrepareException {
    if (Objects.nonNull(mPlayingEntry) && mPlayingEntry.getId() == id) {
        setSupposedToPlay(!isSupposedToPlay());
        return false;
    }

    stop();

    mPlayingEntry = new AudioEntry(id, audio);
    mDuration = audio.getDuration() * 1000;
    mPlayer = new MediaPlayer();

    try {
        mPlayer.setDataSource(mPlayingEntry.getAudio().getLinkMp3());
    } catch (IOException e) {
        throw new PrepareException();
    }

    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mPlayer.setOnPreparedListener(this);
    mPlayer.setOnErrorListener(this);
    mPlayer.setOnCompletionListener(this);

    mSupposedToPlay = true;
    changeStatusTo(STATUS_PREPARING);

    mPlayer.prepareAsync();
    return true;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:30,代碼來源:DefaultVoicePlayer.java


注:本文中的android.media.MediaPlayer.setAudioStreamType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。