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


Java MediaPlayer类代码示例

本文整理汇总了Java中android.media.MediaPlayer的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer类的具体用法?Java MediaPlayer怎么用?Java MediaPlayer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MediaPlayer类属于android.media包,在下文中一共展示了MediaPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: errToStr

import android.media.MediaPlayer; //导入依赖的package包/类
private String errToStr(int framework_err, int impl_err) {
    String msg = null;
    if (framework_err == MediaPlayer.MEDIA_ERROR_IO) {
        msg = "IO Error";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_MALFORMED) {
        msg = "Bitstream unsupported";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) {
        msg = "Invalid progressive playback";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_TIMED_OUT) {
        msg = "Operation time out";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
        msg = "MediaPlayer died";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_UNSUPPORTED) {
        msg = "File spec is not supported in the media framework";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_UNKNOWN) {
        msg = "Unknown error";
    }
    return msg;
}
 
开发者ID:TedaLIEz,项目名称:ParsingPlayer,代码行数:20,代码来源:ParsingPlayerProxy.java

示例2: soundShake

import android.media.MediaPlayer; //导入依赖的package包/类
private void soundShake() {
    try {
        this.mPlayer = MediaPlayer.create(RedPacketSdkManager.getInstance().getApplicationContext(), R.raw.shake_sound);
        if (this.mPlayer != null) {
            this.mPlayer.start();
            this.mPlayer.setOnCompletionListener(new OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {
                    RedPacketDialog.this.mPlayer.release();
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (this.mPlayer != null) {
            this.mPlayer.release();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:RedPacketDialog.java

示例3: 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:CardInfoLink,项目名称:QRScanner,代码行数:22,代码来源:BeepManager.java

示例4: onInfo

import android.media.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
    switch (what) {
        case MediaPlayer.MEDIA_INFO_BUFFERING_START:
            mEventEmitter.receiveEvent(getId(), Events.EVENT_STALLED.toString(), Arguments.createMap());
            break;
        case MediaPlayer.MEDIA_INFO_BUFFERING_END:
            mEventEmitter.receiveEvent(getId(), Events.EVENT_RESUME.toString(), Arguments.createMap());
            break;
        case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
            mEventEmitter.receiveEvent(getId(), Events.EVENT_READY_FOR_DISPLAY.toString(), Arguments.createMap());
            break;

        default:
    }
    return false;
}
 
开发者ID:12d,项目名称:react-native-videoplayer,代码行数:18,代码来源:ReactVideoView.java

示例5: onPrepared

import android.media.MediaPlayer; //导入依赖的package包/类
@Override
    public void onPrepared(MediaPlayer mp) {
        if(mHasVideo) {
            mediaPlayer.start();
            mediaPlayer.setVolume(0,0);
            setVideoSize();
            vidSurface.bringToFront();
            vidSurface.requestFocus();
            MediaController mController = new MediaController(context);
            mController.setMediaPlayer(this);
            mController.setAnchorView(vidSurface);

//        mController.show(0);
            vidSurface.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
        }
    }
 
开发者ID:pawelpaszki,项目名称:youtube_background_android,代码行数:22,代码来源:DownloadedFragment.java

示例6: initializeMedia

import android.media.MediaPlayer; //导入依赖的package包/类
private void initializeMedia() {
    mediaEight[0] = MediaPlayer.create(getApplicationContext(), R.raw.eight_1);
    mediaEight[1] = MediaPlayer.create(getApplicationContext(), R.raw.eight_2);
    mediaEight[2] = MediaPlayer.create(getApplicationContext(), R.raw.eight_3);
    mediaEight[3] = MediaPlayer.create(getApplicationContext(), R.raw.eight_4);
    mediaEight[4] = MediaPlayer.create(getApplicationContext(), R.raw.eight_5);
    mediaEight[5] = MediaPlayer.create(getApplicationContext(), R.raw.eight_7);
    mediaEight[6] = MediaPlayer.create(getApplicationContext(), R.raw.eight_8);

    mediaEight[0].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[1].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[2].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[3].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[4].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[5].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[6].setAudioStreamType(AudioManager.STREAM_MUSIC);
}
 
开发者ID:rollforbugs,项目名称:lokey,代码行数:18,代码来源:IME.java

示例7: playRecord

import android.media.MediaPlayer; //导入依赖的package包/类
private void playRecord() throws IOException {

        File dir = new File(Environment.getExternalStorageDirectory() + File.separator + "AAAAAAAAA");
        if (dir.exists()) {
            File[] files = dir.listFiles();
            if (files.length > 0) {
                mediaPlayer.setDataSource(files[0].getAbsolutePath());
                mediaPlayer.prepare();
                mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mp) {
                        mediaPlayer.start();
                    }
                });
            }
        }
    }
 
开发者ID:NaOHAndroid,项目名称:Logistics-guard,代码行数:18,代码来源:MessageFragment.java

示例8: AndroidMediaPlayer

import android.media.MediaPlayer; //导入依赖的package包/类
public AndroidMediaPlayer() {
    synchronized (mInitLock) {
        mInternalMediaPlayer = new MediaPlayer();
    }
    mInternalMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mInternalListenerAdapter = new AndroidMediaPlayerListenerHolder(this);
    attachInternalListeners();
}
 
开发者ID:Dreamxiaoxuan,项目名称:AndroidTvDemo,代码行数:9,代码来源:AndroidMediaPlayer.java

示例9: playSoundFile

import android.media.MediaPlayer; //导入依赖的package包/类
@ReactMethod
public void playSoundFile(String name, String type) throws IOException {
  if (this.mediaPlayer == null) {
    int soundResID = getReactApplicationContext().getResources().getIdentifier(name, "raw", getReactApplicationContext().getPackageName());
    this.mediaPlayer = MediaPlayer.create(getCurrentActivity(), soundResID);
    this.mediaPlayer.setOnCompletionListener(
      new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer arg0) {
          WritableMap params = Arguments.createMap();
          params.putBoolean("success", true);
          sendEvent(getReactApplicationContext(), "FinishedPlaying", params);
        }
    });
  } else {
    Uri uri = Uri.parse("android.resource://" + getReactApplicationContext().getPackageName() + "/raw/" + name);
    this.mediaPlayer.reset();
    this.mediaPlayer.setDataSource(getCurrentActivity(), uri);
    this.mediaPlayer.prepare();
  }
  this.mediaPlayer.start();
}
 
开发者ID:johnsonsu,项目名称:react-native-sound-player,代码行数:23,代码来源:RNSoundPlayerModule.java

示例10: chimeSound

import android.media.MediaPlayer; //导入依赖的package包/类
public static void chimeSound() {
  ((Activity) MainMenu.getAppContext()).runOnUiThread(new Runnable() {
    public void run() {
      final MediaPlayer mp1 = MediaPlayer.create(MainMenu.getAppContext(), R.raw.chime);
      mp1.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
          mp1.release();
        }

      });
      mp1.start();
    }
  });
}
 
开发者ID:UshalNaidoo,项目名称:Android-Bubble-Game,代码行数:17,代码来源:GamePanel.java

示例11: onCreate

import android.media.MediaPlayer; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //initializing button
    btn = findViewById(R.id.play);

    //initializing mediaPlayer object
    mediaPlayer = new MediaPlayer();

    //setting streaming type
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    //setting clickListener on button
    btn.setOnClickListener(pausePlay);

}
 
开发者ID:stoic1979,项目名称:DroidStreamingDemo,代码行数:19,代码来源:MainActivity.java

示例12: onInfo

import android.media.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
        switch (what) {
                case MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING:
                        // 音频和视频数据不正确
                        break;
                case MediaPlayer.MEDIA_INFO_BUFFERING_START:
                        if (!isFinishing())
                                mSurfaceVideoView.pause();
                        break;
                case MediaPlayer.MEDIA_INFO_BUFFERING_END:
                        if (!isFinishing())
                                mSurfaceVideoView.start();
                        break;
                case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
                        if (DeviceUtils.hasJellyBean()) {
                                mSurfaceVideoView.setBackground(null);
                        } else {
                                mSurfaceVideoView.setBackgroundDrawable(null);
                        }
                        break;
        }
        return false;
}
 
开发者ID:HelloChenJinJun,项目名称:TestChat,代码行数:25,代码来源:ImageDisplayActivity.java

示例13: onSurfaceCreated

import android.media.MediaPlayer; //导入依赖的package包/类
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
    super.onSurfaceCreated(holder);
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setSurface(holder.getSurface());
    try {
        AssetManager assets = getApplicationContext().getAssets();
        AssetFileDescriptor descriptor = assets.openFd("text1.mp4");
        mMediaPlayer.setDataSource(descriptor.getFileDescriptor(),descriptor.getStartOffset(),descriptor.getLength());
        mMediaPlayer.setLooping(true);
        mMediaPlayer.setVolume(1.0f,1.0f);
        mMediaPlayer.prepare();
        mMediaPlayer.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:MirDong,项目名称:VideoWallPager,代码行数:18,代码来源:VideoLiveWallPaper.java

示例14: playAudio

import android.media.MediaPlayer; //导入依赖的package包/类
/**
 * 播放语音文件
 *
 * @param path
 * @param finishCallback
 */
public synchronized void playAudio(String path, Runnable finishCallback) {
  if (onceStart) {
    mediaPlayer.reset();
  }
  tryRunFinishCallback();
  audioPath = path;
  LCIMAudioHelper.this.finishCallback = finishCallback;
  try {
    mediaPlayer.setDataSource(path);
    mediaPlayer.prepare();
    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
      @Override
      public void onCompletion(MediaPlayer mp) {
        tryRunFinishCallback();
      }
    });
    mediaPlayer.start();
    onceStart = true;
  } catch (IOException e) {
  }
}
 
开发者ID:linsir6,项目名称:TripBuyer,代码行数:28,代码来源:LCIMAudioHelper.java

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


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