本文整理汇总了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);
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例13: AndroidMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
public AndroidMediaPlayer() {
synchronized (mInitLock) {
mInternalMediaPlayer = new MediaPlayer();
}
mInternalMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mInternalListenerAdapter = new AndroidMediaPlayerListenerHolder(this);
attachInternalListeners();
}
示例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());
}
示例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;
}