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


Java MediaPlayer.release方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:MRYangY,项目名称:YZxing,代码行数:17,代码来源:BeepManager.java

示例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;
	}
}
 
开发者ID:StickyTolt,项目名称:ForeverLibrary,代码行数:22,代码来源:BeepManager.java

示例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;
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:22,代码来源:BeepManager.java

示例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;
}
 
开发者ID:n76,项目名称:Symphony,代码行数:19,代码来源:MusicService.java

示例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;
	}
}
 
开发者ID:TonnyL,项目名称:Espresso,代码行数:22,代码来源:BeepManager.java

示例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;
  }
}
 
开发者ID:crisfg86,项目名称:Zxing-Custom,代码行数:26,代码来源:BeepManager.java

示例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;
  }
}
 
开发者ID:yun2win,项目名称:tvConnect_android,代码行数:23,代码来源:BeepManager.java

示例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;
}
 
开发者ID:lazyparser,项目名称:xbot_head,代码行数:13,代码来源:AudioManager.java

示例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;
}
 
开发者ID:TonnyL,项目名称:Espresso,代码行数:15,代码来源:BeepManager.java

示例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;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:14,代码来源:BeepManager.java

示例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;
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:15,代码来源:BeepManager.java

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

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

示例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;
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:10,代码来源:HelpUtils.java


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