Back to project page AudioChoice.
The source code is released under:
Apache License
If you think the Android project AudioChoice listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.hwrdprkns.audiochoice; /*www. ja v a 2s . c om*/ import android.content.Context; import android.util.Log; import com.hwrdprkns.audiochoice.server.AudioChoiceLocalServer; import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class BasicProxyMediaPlayer extends BasicStreamMediaPlayer { private final static String TAG = BasicProxyMediaPlayer.class.getSimpleName(); private AudioChoiceLocalServer mLocalServer; private ExecutorService mThreadPool; public BasicProxyMediaPlayer(Context context, IPlayerView playerView) { super(context, playerView); mLocalServer = new AudioChoiceLocalServer(context, getStreamUri()); mThreadPool = Executors.newCachedThreadPool(); } @Override public void start() { if (getMediaPlayer().isPlaying()) return; shouldBePlaying = true; if (!isPrepared) { mThreadPool.execute(new Runnable() { @Override public void run() { startServerAndPlay(); } }); } else { getMediaPlayer().start(); } } @Override protected String getStreamUri() { return "http://localhost:9001"; } private void startServerAndPlay() { try { if (!mLocalServer.isAlive()) { mLocalServer.start(); } getMediaPlayer().setDataSource(getStreamUri()); getMediaPlayer().prepareAsync(); } catch (IOException e) { Log.d(TAG, "Exception when starting" + e.getLocalizedMessage()); } } @Override public void release() { if (mLocalServer != null && mLocalServer.isAlive()) { mLocalServer.stop(); } super.release(); } }