当前位置: 首页>>代码示例>>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;未经允许,请勿转载。