本文整理汇总了Java中android.media.MediaPlayer.create方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.create方法的具体用法?Java MediaPlayer.create怎么用?Java MediaPlayer.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
}
示例2: onStartCommand
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mediaPlayer = MediaPlayer.create(this, R.raw.the_star_spangled_banner);
mediaPlayer.setLooping(true);
mediaPlayer.start();
return super.onStartCommand(intent, flags, startId);
}
示例3: onCreate
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
PhoneFinderConfigManager.setFindingFlag();
Log.i(FindMeActivity.class.getName(), "FindMeActivity called!!!");
audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
originalVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_me);
foundButton = (Button) findViewById(R.id.phone_found_button);
foundButton.setOnClickListener(new FoundButtonListener());
final PhoneFinderConfig config = getConfig();
if (config == null) {
finish();
return;
}
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, config.getVolume(), 0);
mediaPlayer = MediaPlayer.create(this.getBaseContext(), R.raw.findme);
mediaPlayer.setLooping(true);
mediaPlayer.start();
finisherThread = new Thread(new FinisherThread(config));
finisherThread.start();
}
示例4: 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();
}
示例5: play
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void play(int currentTime) {
try {
if (mMediaPlayer != null) {
mMediaPlayer.release();
}
mMediaPlayer = MediaPlayer.create(mContext, Uri.parse(Musicpath));
mMediaPlayer.setOnPreparedListener(new PreparedListener(currentTime));
mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
handler.sendEmptyMessage(4);
}
});
} catch (Exception e) {
Log.e(TAG, "" + e);
}
}
示例6: playAudio
import android.media.MediaPlayer; //导入方法依赖的package包/类
private static void playAudio(final Context context, final String url) throws Exception {
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(context, Uri.parse(url));
}
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
killMediaPlayer();
}
});
mediaPlayer.start();
}
示例7: ReSetSounds
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void ReSetSounds() {
FoldingSounds[0] = MediaPlayer.create(this, R.raw.fold1);
FoldingSounds[1] = MediaPlayer.create(this, R.raw.fold2);
FoldingSounds[2] = MediaPlayer.create(this, R.raw.fold3);
FoldingSounds[3] = MediaPlayer.create(this, R.raw.fold4);
FoldingSounds[4] = MediaPlayer.create(this, R.raw.fold5);
UNFoldingSounds[0] = MediaPlayer.create(this, R.raw.unfold1);
UNFoldingSounds[1] = MediaPlayer.create(this, R.raw.unfold2);
UseHintSound = MediaPlayer.create(this, R.raw.usehint);
StarGotSound[0] = MediaPlayer.create(this, R.raw.stargot);
StarGotSound[1] = MediaPlayer.create(this, R.raw.stargot);
StarGotSound[2] = MediaPlayer.create(this, R.raw.stargot);
}
示例8: createMusicFromResource
import android.media.MediaPlayer; //导入方法依赖的package包/类
public static Music createMusicFromResource(final MusicManager pMusicManager, final Context pContext, final int pMusicResID) throws IOException {
final MediaPlayer mediaPlayer = MediaPlayer.create(pContext, pMusicResID);
mediaPlayer.prepare();
final Music music = new Music(pMusicManager, mediaPlayer);
pMusicManager.add(music);
return music;
}
示例9: loadClip
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void loadClip() {
try {
mp = MediaPlayer.create(this, getResources().getIdentifier(mp_rng,
"raw", this.getPackageName()));
mp.setVolume(mp_vol, mp_vol);
mp.setLooping(true);
} catch (Throwable t) {
}
}
示例10: recaptureMedia
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void recaptureMedia(Activity activity) {
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(activity, R.raw.siren);
}
}
示例11: getMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer getMediaPlayer( String localFileName) {
Uri filePath = Uri.fromFile(new File (IOHelper.getStorageDir(myContext), localFileName));
MediaPlayer mp = MediaPlayer.create(
myContext,
filePath
);
if (mp == null) {
String logMessage = "Can't load file '" + localFileName
+ "'\nIn place: '" + filePath.toString() + "';";
Log.d(MainActivity.LOG_TAG, logMessage);
Toast.makeText(myContext, "Cant load file:" + localFileName, Toast.LENGTH_LONG).show();
}
return mp;
}
示例12: playSound
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void playSound(int resId) {
// Stop current player, if there's one playing
if (null != mCurrentMediaPlayer) {
mCurrentMediaPlayer.stop();
mCurrentMediaPlayer.release();
}
mCurrentMediaPlayer = MediaPlayer.create(mContext, resId);
if (null != mCurrentMediaPlayer) {
mCurrentMediaPlayer.start();
}
}
示例13: playSuffix
import android.media.MediaPlayer; //导入方法依赖的package包/类
protected void playSuffix() {
if(mSuffix) {
mSuffixPlayer = MediaPlayer.create(mContext, R.raw.audio_end_tip);
mSuffixPlayer.setLooping(false);
mSuffixPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mSuffixPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mSuffixPlayer.release();
mSuffixPlayer = null;
}
});
mSuffixPlayer.start();
}
}
示例14: onCreate
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.productions);
mediaPlayer = MediaPlayer.create(this, R.raw.title);
mediaPlayer.setLooping(true);
mediaPlayer.start();
final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
splashImageView.setBackgroundResource(R.drawable.productiongif);
final AnimationDrawable frameAnimation = (AnimationDrawable) splashImageView.getBackground();
splashImageView.post(new Runnable() {
@Override
public void run() {
frameAnimation.start();
}
});
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while (_active && (waited < _splashTime)) {
sleep(100);
if (_active) {
waited += 100;
}
}
} catch (InterruptedException e) {
// do nothing
} finally {
finish();
mediaPlayer.release();
startActivity(new Intent("com.goodguygames.bubblegame.demo.MainMenu"));
}
}
};
splashTread.start();
}
示例15: getPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void getPlayer(Context context, Uri uri) {
mPlayer = MediaPlayer.create(context, uri);
if (null != mPlayer) {
mPlayer.setLooping(false);
// mPlayer.reset();
mPlayer.setOnCompletionListener(this);
}
}