當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaPlayer.setOnErrorListener方法代碼示例

本文整理匯總了Java中android.media.MediaPlayer.setOnErrorListener方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.setOnErrorListener方法的具體用法?Java MediaPlayer.setOnErrorListener怎麽用?Java MediaPlayer.setOnErrorListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.MediaPlayer的用法示例。


在下文中一共展示了MediaPlayer.setOnErrorListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
        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:xiong-it,項目名稱:ZXingAndroidExt,代碼行數:22,代碼來源:BeepManager.java

示例2: 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:alibaba,項目名稱:LuaViewPlayground,代碼行數:22,代碼來源:BeepManager.java

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

示例4: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  try {
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(this.rawBeep);
    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:10045125,項目名稱:QrCode,代碼行數:22,代碼來源:BeepManager.java

示例5: createPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer createPlayer() {
  try {
    MediaPlayer mediaPlayer = new MediaPlayer();
    Uri         ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
    mediaPlayer.setDataSource(context, ringtoneUri);
    mediaPlayer.setLooping(true);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);

    return mediaPlayer;
  } catch (IOException e) {
    Log.e(TAG, "Failed to create player for incoming call ringer");
    return null;
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:17,代碼來源:IncomingRinger.java

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

  AssetFileDescriptor file = activity.getResources().openRawResourceFd(keepass2android.plugin.qr.R.raw.beep);
  try {
    mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    file.close();
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer = null;
  }
  return mediaPlayer;
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:19,代碼來源:BeepManager.java

示例7: MediaPlayerImpl

import android.media.MediaPlayer; //導入方法依賴的package包/類
public MediaPlayerImpl() {
    mMediaPlayer = new MediaPlayer();
    // set audio stream type
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setOnBufferingUpdateListener(bufferingUpdateListener);
    mMediaPlayer.setOnErrorListener(errorListener);
    mMediaPlayer.setOnPreparedListener(preparedListener);
    mMediaPlayer.setOnCompletionListener(completionListener);
    mMediaPlayer.setOnSeekCompleteListener(seekCompleteListener);
    // 不同的音頻源,此回調有的不回調!!!
    // mMediaPlayer.setOnInfoListener(infoListener);

    // 讀取音量和靜音的數據
    currentVolume = (float) MediaPlayerPreferenceUtil.get(context,
            KEY_SP_VOLUME, 0.8f);
    isMute = (boolean) MediaPlayerPreferenceUtil.get(context,
            KEY_SP_MUTE, false);
    // LinkedList
    mediaPlayerListeners = Collections.synchronizedList(new LinkedList<IMediaPlayer.IMediaPlayerListener>());
    posHandler = new PosHandler(Looper.getMainLooper());

    // 來電監聽
    telephonyManager = (TelephonyManager)
            context.getSystemService(Service.TELEPHONY_SERVICE);
    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
 
開發者ID:dueros,項目名稱:dcs-sdk-java,代碼行數:27,代碼來源:MediaPlayerImpl.java

示例8: 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:wp521,項目名稱:MyFire,代碼行數:22,代碼來源:BeepManager.java

示例9: preparePlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void preparePlayer() throws PlayerPrepareException {
    try {
        mediaPlayer = new MediaPlayer();

        mediaPlayer.setDataSource(fileUrl);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setOnPreparedListener(this);
        mediaPlayer.setOnVideoSizeChangedListener(this);
        mediaPlayer.setOnErrorListener(this);
        mediaPlayer.setOnCompletionListener(this);
        mediaPlayer.setLooping(true);

        changeStatusTo(IGifPlayer.IStatus.PREPARING);
        mediaPlayer.prepareAsync();
    } catch (Exception e) {
        changeStatusTo(IGifPlayer.IStatus.INIT);
        throw new PlayerPrepareException();
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:20,代碼來源:DefaultGifPlayer.java

示例10: createPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer createPlayer() {
    try {
        MediaPlayer mediaPlayer = new MediaPlayer();
        Uri         ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

        mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
        mediaPlayer.setDataSource(context, ringtoneUri);
        mediaPlayer.setLooping(true);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);

        return mediaPlayer;
    } catch (IOException e) {
        Log.e(TAG, "Failed to create player for incoming call ringer");
        return null;
    }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:17,代碼來源:IncomingRinger.java

示例11: 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.qr_sacn);
        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:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:22,代碼來源:BeepManager.java

示例12: initPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void initPlayer() {
    mPlayer = new MediaPlayer();
    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mPlayer.setOnErrorListener(this);
    mPlayer.setOnPreparedListener(this);
    mPlayer.setOnBufferingUpdateListener(this);
    mPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
        @Override
        public boolean onInfo(MediaPlayer mp, int what, int extra) {
            Log.d(TAG, "Player onInfo(), what:" + what + ", extra:" + extra);
            return false;
        }
    });
    lockWiFi();
    lockCPU();
}
 
開發者ID:DimaKoz,項目名稱:Android-Foreground-Service-Example,代碼行數:17,代碼來源:SoundService.java

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

示例14: initTrackPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer initTrackPlayer(){
    Log.d(TAG,"initTrackPlayer() entry.");

    MediaPlayer newTrackPlayer = new MediaPlayer();
    //set currentTrackPlayer properties
    newTrackPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    newTrackPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    newTrackPlayer.setOnPreparedListener(this);
    newTrackPlayer.setOnCompletionListener(this);
    newTrackPlayer.setOnErrorListener(this);
    return newTrackPlayer;
}
 
開發者ID:n76,項目名稱:Symphony,代碼行數:13,代碼來源:MusicService.java

示例15: toggle

import android.media.MediaPlayer; //導入方法依賴的package包/類
public boolean toggle(int id, VoiceMessage audio) throws PrepareException {
    if (Objects.nonNull(mPlayingEntry) && mPlayingEntry.getId() == id) {
        setSupposedToPlay(!isSupposedToPlay());
        return false;
    }

    stop();

    mPlayingEntry = new AudioEntry(id, audio);
    mDuration = audio.getDuration() * 1000;
    mPlayer = new MediaPlayer();

    try {
        mPlayer.setDataSource(mPlayingEntry.getAudio().getLinkMp3());
    } catch (IOException e) {
        throw new PrepareException();
    }

    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mPlayer.setOnPreparedListener(this);
    mPlayer.setOnErrorListener(this);
    mPlayer.setOnCompletionListener(this);

    mSupposedToPlay = true;
    changeStatusTo(STATUS_PREPARING);

    mPlayer.prepareAsync();
    return true;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:30,代碼來源:DefaultVoicePlayer.java


注:本文中的android.media.MediaPlayer.setOnErrorListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。