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


Java MediaPlayer.create方法代码示例

本文整理汇总了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();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:RedPacketDialog.java

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

}
 
开发者ID:Jamjomjara,项目名称:snu-artoon,代码行数:9,代码来源:MusicService.java

示例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();
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:27,代码来源:FindMeActivity.java

示例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();
}
 
开发者ID:johnsonsu,项目名称:react-native-sound-player,代码行数:23,代码来源:RNSoundPlayerModule.java

示例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);
    }
}
 
开发者ID:fikyair,项目名称:musicplayer,代码行数:20,代码来源:MusicPlayerService.java

示例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();
}
 
开发者ID:mmjang,项目名称:ankihelper,代码行数:13,代码来源:PlayAudioManager.java

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

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

示例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) {
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:10,代码来源:Alarm.java

示例10: recaptureMedia

import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void recaptureMedia(Activity activity) {
    if (mediaPlayer == null) {
        mediaPlayer = MediaPlayer.create(activity, R.raw.siren);
    }
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:7,代码来源:AlertsView.java

示例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;
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:16,代码来源:SoundHelper.java

示例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();
	}
}
 
开发者ID:liupengandroid,项目名称:ywApplication,代码行数:13,代码来源:SoundPullEventListener.java

示例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();
    }
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:16,代码来源:BaseAudioControl.java

示例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();
}
 
开发者ID:UshalNaidoo,项目名称:Android-Bubble-Game,代码行数:44,代码来源:SplashScreen.java

示例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);
        }
    }
 
开发者ID:piyell,项目名称:NeteaseCloudMusic,代码行数:9,代码来源:PlayerManager.java


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