Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - MediaPlayer streaming displaying a Progress Dialog before playing
    primarykey
    data
    text
    <p>In my application, I will playing music from URL. So it would still take some time to play the audio since it is through streaming. I wanted to implement a ProgressDialog while waiting for the <code>MediaPlayer</code> to play/start.</p> <p>Here is my method for playing the audio: public void playMedia(String songIndex) {</p> <pre><code> ProgressDialog pDialog; pDialog = new ProgressDialog(context); pDialog.setMessage("Loading. . . "); pDialog.setCancelable(false); pDialog.show(); Uri songUri = Uri.parse(songIndex); try { mp.setDataSource(context, songUri); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.prepare(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ pDialog.dismiss(); } if(mp!=null) mp.start(); } </code></pre> <p>This is how I tried to implement it. But it did not work. And i have Exceptions like this:</p> <pre><code> 08-27 19:48:13.896: E/InputEventReceiver(8798): Exception dispatching input event. 08-27 19:48:13.896: E/MessageQueue-JNI(8798): Exception in MessageQueue callback: handleReceiveCallback 08-27 19:48:13.906: E/MessageQueue-JNI(8798): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewRootImpl.setView(ViewRootImpl.java:599) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.app.Dialog.show(Dialog.java:285) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at com.app.adapters.MyRowAdapter.playMedia(MyRowAdapter.java:126) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at com.app.adapters.MyRowAdapter$2$4.onTouch(MyRowAdapter.java:522) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.View.dispatchTouchEvent(View.java:7185) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2280) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2023) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2280) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2023) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2280) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2023) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2280) 08-27 19:48:13.906: E/MessageQueue-JNI(8798): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2023) </code></pre> <p>Are there other ways to implement this? Like where should i put this one? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload