本文整理汇总了Java中android.media.MediaPlayer.start方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.start方法的具体用法?Java MediaPlayer.start怎么用?Java MediaPlayer.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playAllAsync
import android.media.MediaPlayer; //导入方法依赖的package包/类
public void playAllAsync() {
Thread r = new Thread() {
@Override
public void run() {
int counter = 0;
for (MediaPlayer m : loadedSounds) {
Log.d(MainActivity.LOG_TAG, "Playing sound no. " + counter);
m.start();
while (m.isPlaying()) {
try {
Thread.sleep(100,0); // lower cpu if we wait and not just busy wait
} catch (InterruptedException e) { e.printStackTrace();}
}
counter++;
}
raisePlayBackFinishEvent();
}
};
r.start();
}
示例2: resume
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* resume playing
*
* @return
*/
public synchronized UDAudio resume() {
final MediaPlayer player = getMediaPlayer();
if (player != null && player.isPlaying() == false) {
try {
if (player.getCurrentPosition() > 0) {
player.start();
} else {
play(mUriOrName, mLoopTimes);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return this;
}
示例3: playClick
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void playClick(int keyCode) {
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
switch (keyCode) {
case 0x20:
am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
break;
case Keyboard.KEYCODE_DONE:
case 0x0a:
am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
break;
case Keyboard.KEYCODE_DELETE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
break;
case 0x38:
if (prefs.getBoolean("pref_eight_enable", false)) {
// Play random "eight" sound
MediaPlayer mPlayer = mediaEight[rand.nextInt(mediaEight.length)];
mPlayer.seekTo(0);
mPlayer.start();
}
break;
default:
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
}
}
示例4: playRecording
import android.media.MediaPlayer; //导入方法依赖的package包/类
public static void playRecording(Context context, MediaPlayer mediaPlayer, String recordingName) {
try {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.reset(); //Before a setDataSource call, you need to reset MP obj.
mediaPlayer.setDataSource(context.getFilesDir().getAbsolutePath() + "/" + recordingName);
mediaPlayer.prepare();
mediaPlayer.start();
} else {
mediaPlayer.reset(); //Before a setDataSource call, you need to reset MP obj.
mediaPlayer.setDataSource(context.getFilesDir().getAbsolutePath() + "/" + recordingName);
mediaPlayer.prepare();
mediaPlayer.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: onIncomingCallRinging
import android.media.MediaPlayer; //导入方法依赖的package包/类
public void onIncomingCallRinging() {
int ringerMode = NotificationUtil.getRingerMode(this);
if(ringerMode != AudioManager.RINGER_MODE_SILENT){
if(ringerMode == AudioManager.RINGER_MODE_VIBRATE){
mVibrator = (Vibrator) RongContext.getInstance().getSystemService(Context.VIBRATOR_SERVICE);
mVibrator.vibrate(new long[] {500, 1000}, 0);
} else {
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(this, uri);
mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
示例6: onPrepared
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onPrepared(MediaPlayer mp) {
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
setVideoViewSize(TYPE_NORMAL);
mp.start();
mLoadingView.setVisibility(View.INVISIBLE);
mMediaSkb.setMax(mVideoPlayer.getDuration());
mTotalDuration.setText(TimeUtils.toTimeStr(mVideoPlayer.getDuration()));
mHandler.sendEmptyMessageDelayed(REFRESH_MESSAGE, 1000);
if (mUri != null) {
mMediaName.setText(mUri.toString());
} else if (mMediaItems != null) {
if (mMediaItems.get(mCurrentPlayIndex) != null)
mMediaName.setText(mMediaItems.get(mCurrentPlayIndex).getDisplayName());
} else if (!TextUtils.isEmpty(mPath)) {
mMediaName.setText(mPath);
}
}
示例7: play
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* 播放
*/
private void play(SurfaceHolder surfaceHolder,String videoPath){
mediaPlayer = new MediaPlayer();
// 设置多媒体流类型
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// 设置用于展示mediaPlayer的容器
mediaPlayer.setSurface(surfaceHolder.getSurface());
// mediaPlayer.setDisplay(surfaceHolder);//用这个方法会报 Wallpapers do not support keep screen on
try {
mediaPlayer.setDataSource(videoPath);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.setLooping(true);
} catch (Exception e) {
Log.i("通知", "播放过程中出现了错误哦");
}
}
示例8: startPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void startPlayer() {
mPlayer = new MediaPlayer();
mPlayer.setOnErrorListener(mErrorListener);
try {
isAlarmRinging = true;
// add vibration to alarm alert if it is set
//if (App.getState().settings().vibrate()) {
mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
mHandler.post(mVibrationRunnable);
//}
// Player setup is here
String ringtone;// = App.getState().settings().ringtone();
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
// && ringtone.startsWith("content://media/external/")
// && checkSelfPermission(
// Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM).toString();
//}
mPlayer.setDataSource(this, Uri.parse(ringtone));
mPlayer.setLooping(true);
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mPlayer.setVolume(mVolumeLevel, mVolumeLevel);
mPlayer.prepare();
mPlayer.start();
//if (App.getState().settings().ramping()) {
// mHandler.postDelayed(mVolumeRunnable, VOLUME_INCREASE_DELAY);
//} else {
mPlayer.setVolume(MAX_VOLUME, MAX_VOLUME);
//}
} catch (Exception e) {
isAlarmRinging = false;
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
stopSelf();
}
}
示例9: onReceive
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
MediaPlayer mp = MediaPlayer.create(context, R.raw.ferry_sound);
mp.start();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My GlobalData");
wl.acquire();
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
long[] s = { 0, 100, 10, 500, 10, 100, 0, 500, 10, 100, 10, 500 };
vibrator.vibrate(s, -1);
}
示例10: playSound
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void playSound(int resID) {
if (!mPlaySound) {
return;
}
MediaPlayer mp = MediaPlayer.create(this, resID);
if (mp != null) {
mp.start();
}
}
示例11: onPrepared
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
isPlaying = true;
this.duration = mediaPlayer.getDuration();
this.currentTime = mediaPlayer.getCurrentPosition();
updateTimeAudio();
if (jcPlayerServiceListeners != null) {
for (JcPlayerView.JcPlayerViewServiceListener jcPlayerServiceListener : jcPlayerServiceListeners) {
jcPlayerServiceListener.updateTitle(currentJcAudio.getTitle());
jcPlayerServiceListener.onPreparedAudio(currentJcAudio.getTitle(), mediaPlayer.getDuration());
}
}
if (notificationListener != null) {
notificationListener.updateTitle(currentJcAudio.getTitle());
notificationListener.onPreparedAudio(currentJcAudio.getTitle(), mediaPlayer.getDuration());
}
if (jcPlayerStatusListeners != null) {
for (JcPlayerView.JcPlayerViewStatusListener jcPlayerViewStatusListener : jcPlayerStatusListeners) {
jcStatus.setJcAudio(currentJcAudio);
jcStatus.setPlayState(JcStatus.PlayState.PLAY);
jcStatus.setDuration(duration);
jcStatus.setCurrentPosition(currentTime);
jcPlayerViewStatusListener.onPreparedAudioStatus(jcStatus);
}
}
}
示例12: startPlaying
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void startPlaying() {
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(mAudioFileName);
mPlayer.prepare();
mPlayer.start();
mRecordingState = STATE_PLAYING;
refreshState();
mPlayer.setOnCompletionListener(stoppedPlaying);
} catch (IOException e) {
log(getKey() + ": startPlaying failed: " + e.getMessage());
}
}
示例13: onClickCheckBox
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onClickCheckBox(int p,CheckBox checkBox,TextView title)
{
HashMap<String,String> map = mArrayList.get(p);
if(checkBox.isChecked())
{
title.setPaintFlags(title.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
MediaPlayer player = MediaPlayer.create(getContext(),R.raw.ding);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
if(player.isPlaying())
player.stop();
else
player.start();
mTodo.updateData(keyName,1,map.get("id"));
mArrayList = mTodo.getData(keyName);
}
else
{
title.setPaintFlags(title.getPaintFlags()&(~Paint.STRIKE_THRU_TEXT_FLAG));
mTodo.updateData(keyName,0,map.get("id"));
mArrayList = mTodo.getData(keyName);
}
}
示例14: playAssetsMusic
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* 打开工程assets目录下的音乐文件
*
* @param con
* @param filename
* @return
*/
public static void playAssetsMusic(Context con, String filename) throws IOException {
MediaPlayer m = new MediaPlayer();
AssetFileDescriptor descriptor = con.getAssets().openFd(
filename);
m.setDataSource(descriptor.getFileDescriptor(),
descriptor.getStartOffset(), descriptor.getLength());
descriptor.close();
m.prepare();
m.start();
}
示例15: show
import android.media.MediaPlayer; //导入方法依赖的package包/类
@UiThread
static void show(@NonNull Activity activity, @NonNull IE_Message message) throws WindowManager.BadTokenException {
PW_AlertMessage alert = PW_AlertMessage._CurrentVisible;
if (alert != null) {
if(alert._MessageID == message.conversation_message_id) { //Already displaying that message
alert.bindMessage(message);
alert.abortFadeOut();
alert.getContentView().postDelayed(alert._FadeOutAfterTOT, AUTO_FADE_OUT_DELAY);
return;
}
if(activity == alert.getActivity()) {
alert.fadeOut();
} else {
alert.dismissAllowingStateLoss();
}
}
alert = new PW_AlertMessage(activity);
alert.bindMessage(message);
int top_offset_fix = 0;
View decorView = activity.getWindow().getDecorView();
if (decorView instanceof ViewGroup) {
ViewGroup decorViewGroup = (ViewGroup) decorView;
if (decorViewGroup.getChildCount() == 1) {
top_offset_fix = decorViewGroup.getChildAt(0).getPaddingTop();
}
}
alert.showAtLocation(activity.getWindow().getDecorView(), Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, top_offset_fix);
PW_AlertMessage._CurrentVisible = alert;
alert.getContentView().postDelayed(alert._FadeOutAfterTOT, AUTO_FADE_OUT_DELAY);
MediaPlayer mp = MediaPlayer.create(activity, R.raw.notif_2);
mp.setOnCompletionListener(mp1 -> {
mp1.reset();
mp1.release();
});
mp.start();
}