Search in sources :

Example 26 with MediaPlayer

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;
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) MediaPlayer(android.media.MediaPlayer)

Example 27 with MediaPlayer

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;
        }
    }
}
Also used : IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 28 with MediaPlayer

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;
//    }
}
Also used : MediaPlayer(android.media.MediaPlayer)

Example 29 with MediaPlayer

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;
}
Also used : MediaPlayer(android.media.MediaPlayer)

Example 30 with MediaPlayer

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;
}
Also used : MediaPlayer(android.media.MediaPlayer)

Aggregations

MediaPlayer (android.media.MediaPlayer)365 IOException (java.io.IOException)177 LargeTest (android.test.suitebuilder.annotation.LargeTest)60 AudioEffect (android.media.audiofx.AudioEffect)54 AudioManager (android.media.AudioManager)49 AssetFileDescriptor (android.content.res.AssetFileDescriptor)27 EnergyProbe (com.android.mediaframeworktest.functional.EnergyProbe)24 MediaRecorder (android.media.MediaRecorder)18 Uri (android.net.Uri)16 SurfaceHolder (android.view.SurfaceHolder)16 CamcorderProfile (android.media.CamcorderProfile)12 VideoView (android.widget.VideoView)11 File (java.io.File)11 Intent (android.content.Intent)8 OnPreparedListener (android.media.MediaPlayer.OnPreparedListener)7 Surface (android.view.Surface)7 MediaController (android.widget.MediaController)7 MediaFormat (android.media.MediaFormat)6 UtteranceProgressDispatcher (android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher)6 View (android.view.View)6