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


Java MediaPlayer.stop方法代码示例

本文整理汇总了Java中android.media.MediaPlayer.stop方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.stop方法的具体用法?Java MediaPlayer.stop怎么用?Java MediaPlayer.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaPlayer的用法示例。


在下文中一共展示了MediaPlayer.stop方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stop

import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
 * stop playing audio
 *
 * @return
 */
public synchronized UDAudio stop() {
    final MediaPlayer player = getMediaPlayer();
    if (player != null && player.isPlaying()) {
        try {
            player.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return this;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:17,代码来源:UDAudio.java

示例2: onCompletion

import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
 * @param mp
 */
@Override
public void onCompletion(MediaPlayer mp) {
    if (mp != null) {
        synchronized (mp) {
            try {
                mp.stop();
                mp.reset();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    if (mCallback != null) {
        LuaUtil.callFunction(LuaUtil.getFunction(mCallback, "onComplete", "OnComplete"));
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:21,代码来源:UDAudio.java

示例3: 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

示例4: onPlayClick

import android.media.MediaPlayer; //导入方法依赖的package包/类
public void onPlayClick(View v) {
    if (!mPlaying) {
        try {
            mPlayer = new MediaPlayer();
            AssetFileDescriptor fd = getResources().openRawResourceFd(R.raw.space);
            mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
            mPlayer.setOnCompletionListener(mOnCompletionListener);
            mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mPlayer.prepare();
            mPlayer.start();
            mPlaying = true;
            setState(STATE_PLAYING);
        } catch (IOException e) {
            Log.e(TAG, "error trying to play a sound");
        }
    } else {
        mPlayer.setOnCompletionListener(null);
        mPlayer.stop();
        mPlayer.release();
        mPlayer = null;
        mPlaying = false;
        setState(STATE_IDLE);
    }
}
 
开发者ID:nasa,项目名称:astrobee_android,代码行数:25,代码来源:MainActivity.java

示例5: onPlaybackClick

import android.media.MediaPlayer; //导入方法依赖的package包/类
public void onPlaybackClick(View v) {
    File f = new File(getExternalFilesDir(null), "recording.mp4");

    if (!mPlaying) {
        try {
            mPlayer = new MediaPlayer();
            mPlayer.setDataSource(f.getAbsolutePath());
            mPlayer.setOnCompletionListener(mOnCompletionListener);
            mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mPlayer.prepare();
            mPlayer.start();
            mPlaying = true;
            setState(STATE_PLAYING_BACK);
        } catch (IOException e) {
            Log.e(TAG, "error trying to playback recording");
        }
    } else {
        mPlayer.setOnCompletionListener(null);
        mPlayer.stop();
        mPlayer.release();
        mPlayer = null;

        mPlaying = false;
        setState(STATE_IDLE);
    }
}
 
开发者ID:nasa,项目名称:astrobee_android,代码行数:27,代码来源:MainActivity.java

示例6: 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

示例7: 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

示例8: stopMedia

import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
 * 使用完MediaPlayer需要回收资源。MediaPlayer是很消耗系统资源的,所以在使用完MediaPlayer,不要等待系统自动回收,最好是主动回收资源。
 */
private void stopMedia(MediaPlayer mediaPlayer) {
    if (mediaPlayer != null && mediaPlayer.isPlaying()) {
        mediaPlayer.stop();
        mediaPlayer.release();
        mediaPlayer = null;
    }

}
 
开发者ID:orchidTJJ,项目名称:getword,代码行数:12,代码来源:MainActivity.java

示例9: stop

import android.media.MediaPlayer; //导入方法依赖的package包/类
@ReactMethod
public void stop(final Integer key) {
  MediaPlayer player = this.playerPool.get(key);
  if (player != null && player.isPlaying()) {
    player.stop();
  }
}
 
开发者ID:remobile,项目名称:react-native-audio,代码行数:8,代码来源:RCTAudio.java

示例10: releaseMemory

import android.media.MediaPlayer; //导入方法依赖的package包/类
public void releaseMemory() {
    for(int i=0;i<audioMap.size();i++) {
        MediaPlayer mp = audioMap.remove(i);
        if (mp.isPlaying()) {
            mp.stop();
        }
        mp.release();
    }
    audioMap = null;
    isPlaying = false;
    currentId = CURRENT_NOT_PLAYING;
}
 
开发者ID:lazyparser,项目名称:xbot_head,代码行数:13,代码来源:AudioManager.java

示例11: stopPlaying

import android.media.MediaPlayer; //导入方法依赖的package包/类
@SuppressWarnings({"unused", "UnusedAssignment"})
public static void stopPlaying(MediaPlayer mediaPlayer) {
    if (mediaPlayer != null) {
        mediaPlayer.stop();
        mediaPlayer.release();
        mediaPlayer = null;
    }
}
 
开发者ID:Cesarsk,项目名称:Say_it,代码行数:9,代码来源:UtilityRecordings.java

示例12: onCompletion

import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
	public void onCompletion(MediaPlayer mp) {
		mPosition = 0;
		try {
			mp.stop();
			isPlaying = false;
			if (mCurrentMessage != null) {
				mCurrentMessage.isPlaying = false;
			}
			if (mCallbak != null) {
				mCallbak.endAnimation();
				mCallbak.onPlayEnd(mCurrentMessage);
				mCurrentMessage = null;
				mCallbak = null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 
开发者ID:lennyup,项目名称:react-native-udesk,代码行数:20,代码来源:RecordPlay.java


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