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


Java MediaPlayer.reset方法代码示例

本文整理汇总了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;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:18,代码来源:AlertPlugin.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: destroyAdPlayers

import android.media.MediaPlayer; //导入方法依赖的package包/类
private void destroyAdPlayers() {
	for (MediaPlayer player : adPlayers) {
		player.reset();
		player.release();
	}
	
	adPlayers.clear();
}
 
开发者ID:lbbniu,项目名称:CCDownload,代码行数:9,代码来源:ADMediaPlayActivity.java

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

示例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;
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:34,代码来源:MultiPlayer.java

示例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);
	}
}
  }
 
开发者ID:vassela,项目名称:AC2RD,代码行数:37,代码来源:Replayer.java

示例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();
}
 
开发者ID:malah-code,项目名称:Open-Quran-Radio,代码行数:8,代码来源:PlayerService.java

示例9: onError

import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
    mediaPlayer.reset();
    return false;
}
 
开发者ID:htqqdd,项目名称:music_player,代码行数:6,代码来源:PlayService.java

示例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);
		}
	}
}
  }
 
开发者ID:vassela,项目名称:AC2RD,代码行数:42,代码来源:Replayer.java

示例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;
	} 
开发者ID:lennyup,项目名称:react-native-udesk,代码行数:10,代码来源:RecordPlay.java


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