当前位置: 首页>>代码示例>>Java>>正文


Java MediaPlayer.start方法代码示例

本文整理汇总了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();
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:27,代码来源:SoundHelper.java

示例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;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:21,代码来源:UDAudio.java

示例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);
    }
}
 
开发者ID:rollforbugs,项目名称:lokey,代码行数:26,代码来源:IME.java

示例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();
    }
}
 
开发者ID:Cesarsk,项目名称:Say_it,代码行数:19,代码来源:UtilityRecordings.java

示例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();
            }
        }
    }
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:21,代码来源:BaseCallActivity.java

示例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);
    }
}
 
开发者ID:iPanelkegy,项目名称:MobileMedia,代码行数:20,代码来源:SystemVideoPlayerActivity.java

示例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("通知", "播放过程中出现了错误哦");
            }
        }
 
开发者ID:WanAndroid,项目名称:LiveWallPaper,代码行数:21,代码来源:CameraLiveWallpaper.java

示例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();
  }
}
 
开发者ID:Arjun-sna,项目名称:LocationAware,代码行数:40,代码来源:LocationAwareService.java

示例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);
}
 
开发者ID:atulgpt,项目名称:TimeTrix,代码行数:12,代码来源:Alarm.java

示例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();
	}
}
 
开发者ID:zipzapdat,项目名称:AndroFish,代码行数:10,代码来源:AndroidFishEatingFish.java

示例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);
        }
    }
}
 
开发者ID:yusufkocak1,项目名称:TMP-Music_player,代码行数:31,代码来源:JcPlayerService.java

示例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());
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:14,代码来源:QuickRecordTile.java

示例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);

    }
}
 
开发者ID:Salman544,项目名称:Todo_App,代码行数:30,代码来源:TodoFragment.java

示例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();
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:18,代码来源:FileUtil.java

示例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();
}
 
开发者ID:customerly,项目名称:Customerly-Android-SDK,代码行数:37,代码来源:PW_AlertMessage.java


注:本文中的android.media.MediaPlayer.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。