本文整理汇总了Java中android.media.MediaPlayer.release方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.release方法的具体用法?Java MediaPlayer.release怎么用?Java MediaPlayer.release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.release方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
try (AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep)) {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
mediaPlayer.setOnErrorListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setLooping(false);
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例2: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnErrorListener(this);
try {
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例3: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setOnErrorListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setLooping(false);
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例4: prepareTrack
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer prepareTrack(int trackIndex) {
MediaPlayer mp = initTrackPlayer();
Song songToPlay = songs.get(trackIndex); //get song info
long currSong = songToPlay.getId(); //set uri
Uri trackUri = ContentUris.withAppendedId(
android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
currSong);
try {
mp.setDataSource(getApplicationContext(), trackUri);
} catch (Exception e) {
Log.e("MUSIC SERVICE", "Error setting data source", e);
mp.release();
return null;
}
mp.prepareAsync();
return mp;
}
示例5: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnErrorListener(this);
try {
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例6: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity,modes mode) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnErrorListener(this);
try {
AssetFileDescriptor file;
if(mode==modes.SINGLE)
file = activity.getResources().openRawResourceFd(R.raw.beep);
else
file = activity.getResources().openRawResourceFd(R.raw.triplebeep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例7: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnErrorListener(this);
try {
AssetFileDescriptor file = activity.getResources()
.openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例8: 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;
}
示例9: onError
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
// we are finished, so put up an appropriate error toast if required
// and finish
activity.finish();
} else {
// possibly media player error, so release and recreate
mp.release();
mediaPlayer = null;
updatePrefs();
}
return true;
}
示例10: onError
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
// we are finished, so put up an appropriate error toast if required and finish
activity.finish();
} else {
// possibly media player error, so release and recreate
mp.release();
mediaPlayer = null;
updatePrefs();
}
return true;
}
示例11: onError
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
// we are finished, so put up an appropriate error toast if required
// and finish
activity.finish();
} else {
// possibly media player error, so release and recreate
mp.release();
mediaPlayer = null;
updatePrefs();
}
return true;
}
示例12: 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);
}
}
}
示例13: release
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* release resource
*
* @return
*/
public synchronized UDAudio release() {
final MediaPlayer player = getMediaPlayer();
if (player != null) {
try {
player.release();
} catch (Exception e) {
e.printStackTrace();
}
}
return this;
}
示例14: mediaDuration
import android.media.MediaPlayer; //导入方法依赖的package包/类
public static int mediaDuration(Context context,String path){
MediaPlayer mp = MediaPlayer.create(context, Uri.parse(path));
if(mp==null){
return 0;
}
int duration = mp.getDuration();
mp.release();
return duration;
}