use of android.media.MediaPlayer in project LuaViewSDK by alibaba.
the class UDAudio method play.
/**
* start playing audio
*
* @param uriOrName
* @param loopTimes
* @return
*/
public synchronized UDAudio play(String uriOrName, Integer loopTimes) {
stopAndReset();
if (uriOrName != null && uriOrName.equals(this.mUriOrName) == false) {
//url 不同
this.mUriOrName = uriOrName;
}
if (loopTimes != null) {
this.mLoopTimes = loopTimes;
}
if (this.mUriOrName != null) {
final MediaPlayer player = getMediaPlayer();
if (player != null && player.isPlaying() == false) {
String uri = null;
boolean assetFileExist = false;
if (URLUtil.isNetworkUrl(this.mUriOrName) || URLUtil.isFileUrl(this.mUriOrName) || URLUtil.isAssetUrl(this.mUriOrName)) {
//net & file & asset
uri = this.mUriOrName;
} else {
//plain text, use as file path
uri = getLuaResourceFinder().buildFullPathInBundleOrAssets(this.mUriOrName);
assetFileExist = AssetUtil.exists(getContext(), uri);
}
try {
if (assetFileExist) {
final AssetFileDescriptor descriptor = getContext().getAssets().openFd(uri);
player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
} else {
player.setDataSource(uri);
}
player.setOnErrorListener(this);
player.setOnCompletionListener(this);
player.setOnPreparedListener(this);
player.setLooping((this.mLoopTimes != null && this.mLoopTimes > 1) ? true : false);
player.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return this;
}
use of android.media.MediaPlayer in project Lazy by l123456789jy.
the class RecorderControl method startPlaying.
/**
*
* @param Filename Filename
* @param completion completion
*/
//
public void startPlaying(String Filename, OnCompletionListener completion) {
if (!playState) {
if (mPlayer == null) {
mPlayer = new MediaPlayer();
}
try {
mPlayer.setDataSource(Filename);
mPlayer.prepare();
playState = true;
mPlayer.start();
mPlayer.setOnCompletionListener(completion);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
if (mPlayer.isPlaying()) {
mPlayer.stop();
playState = false;
// startPlaying(Filename);
} else {
playState = false;
}
}
}
use of android.media.MediaPlayer in project zxingfragmentlib by mitoyarzun.
the class BeepManager method buildMediaPlayer.
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnErrorListener(this);
// mediaPlayer.release();
return null;
// }
}
use of android.media.MediaPlayer in project AndEngine by nicolasgramlich.
the class MusicFactory method createMusicFromAssetFileDescriptor.
public static Music createMusicFromAssetFileDescriptor(final MusicManager pMusicManager, final AssetFileDescriptor pAssetFileDescriptor) throws IOException {
final MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(pAssetFileDescriptor.getFileDescriptor(), pAssetFileDescriptor.getStartOffset(), pAssetFileDescriptor.getLength());
mediaPlayer.prepare();
final Music music = new Music(pMusicManager, mediaPlayer);
pMusicManager.add(music);
return music;
}
use of android.media.MediaPlayer in project AndEngine by nicolasgramlich.
the class MusicFactory method createMusicFromResource.
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;
}
Aggregations