本文整理汇总了Java中android.media.MediaPlayer.reset方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.reset方法的具体用法?Java MediaPlayer.reset怎么用?Java MediaPlayer.reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.reset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDuration
import android.media.MediaPlayer; //导入方法依赖的package包/类
public static int getDuration(MediaPlayer mediaPlayer, AssetFileDescriptor afd) {
int duration = 500;
try {
mediaPlayer.reset();
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
mediaPlayer.prepare();
duration = mediaPlayer.getDuration();
} catch(IOException e) {
Log.e(TAG, e.toString());
}
mediaPlayer.reset();
return duration;
}
示例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"));
}
}
示例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();
}
}
示例4: destroyAdPlayers
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void destroyAdPlayers() {
for (MediaPlayer player : adPlayers) {
player.reset();
player.release();
}
adPlayers.clear();
}
示例5: reset
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* reset from error state
*
* @return
*/
public synchronized UDAudio reset() {
final MediaPlayer player = getMediaPlayer();
if (player != null) {
try {
player.reset();
} catch (Exception e) {
e.printStackTrace();
}
}
return this;
}
示例6: setDataSourceImpl
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* @param player The {@link MediaPlayer} to use
* @param path The path of the file, or the http/rtsp URL of the stream
* you want to play
* @return True if the <code>player</code> has been prepared and is
* ready to play, false otherwise
*/
private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) {
if (context == null) {
return false;
}
try {
player.reset();
player.setOnPreparedListener(null);
if (path.startsWith("content://")) {
player.setDataSource(context, Uri.parse(path));
} else {
player.setDataSource(path);
}
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.prepare();
} catch (Exception e) {
return false;
}
player.setOnCompletionListener(this);
player.setOnErrorListener(this);
final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName());
intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
context.sendBroadcast(intent);
return true;
}
示例7: initMediaplayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
public void initMediaplayer()
{
try
{
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(recordFileAbsolutePath);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.prepare();
}
catch (Exception e)
{
try
{
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
}
catch (Exception e2)
{
Log.w("Replayer", "initMediaplayer : " + getApplicationContext().getString(R.string.log_replayer_echec_player_close) + " : " + e);
databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_replayer_echec_player_close), new Date().getTime(), 2, false);
Log.e("Replayer", "initMediaplayer : " + getApplicationContext().getString(R.string.log_replayer_error_player_init) + " : " + e);
databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_replayer_error_player_init), new Date().getTime(), 1, false);
telephoneCallNotifier.displayToast(getApplicationContext(), getApplicationContext().getString(R.string.notification_replayer_error_launch_toast), true);
}
finally
{
Log.e("Replayer", "initMediaplayer : " + getApplicationContext().getString(R.string.log_replayer_error_player_init) + " : " + e);
databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_replayer_error_player_init), new Date().getTime(), 1, false);
telephoneCallNotifier.displayToast(getApplicationContext(), getApplicationContext().getString(R.string.notification_replayer_error_launch_toast), true);
}
}
}
示例8: onCompletion
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onCompletion(MediaPlayer mp) {
LogHelper.w(LOG_TAG, "Resuming playback after completion / signal loss. Player instance count: " + mPlayerInstanceCounter);
mp.reset();
mPlayerInstanceCounter++;
initializeMediaPlayer();
}
示例9: onError
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
mediaPlayer.reset();
return false;
}
示例10: initWavMediaplayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
public void initWavMediaplayer(ReplayFileReader replayFileReader)
{
boolean isValidAudioReplayWavFile = replayFileReader.isValidAudioReplayWavFile(getApplicationContext(), recordFileAbsolutePath);
if(isValidAudioReplayWavFile == true)
{
try
{
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(recordFileAbsolutePath);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.prepare();
}
catch (Exception e)
{
try
{
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
}
catch (Exception e2)
{
Log.w("Replayer", "initWavMediaplayer : " + getApplicationContext().getString(R.string.log_replayer_echec_player_close) + " : " + e);
databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_replayer_echec_player_close), new Date().getTime(), 2, false);
Log.e("Replayer", "initWavMediaplayer : " + getApplicationContext().getString(R.string.log_replayer_error_player_init) + " : " + e);
databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_replayer_error_player_init), new Date().getTime(), 1, false);
telephoneCallNotifier.displayToast(getApplicationContext(), getApplicationContext().getString(R.string.notification_replayer_error_launch_toast), true);
}
finally
{
Log.e("Replayer", "initWavMediaplayer : " + getApplicationContext().getString(R.string.log_replayer_error_player_init) + " : " + e);
databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_replayer_error_player_init), new Date().getTime(), 1, false);
telephoneCallNotifier.displayToast(getApplicationContext(), getApplicationContext().getString(R.string.notification_replayer_error_launch_toast), true);
}
}
}
}
示例11: onError
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
arg0.reset();
isPlaying = false;
if (mCurrentMessage != null) {
mCurrentMessage.isPlaying = false;
}
return true;
}