Note that there are some explanatory texts on larger screens.

plurals
  1. POError checking MediaPlayer android
    primarykey
    data
    text
    <p>I'm making a simple mediaplayer app that downloads a song from a predetermined URL then let's the user play, pause and stop the song, among other things. My only problem right now is that if the user tries to play the song before they download it the application force closes. </p> <p>My first instinct is to create a global bool flag, set it to true when my download service downloads the file, and then use that flag to error check before I let the play.onclick button run the play service. </p> <p>So for example:</p> <pre><code>play.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (downloadFlag == true){ Intent intent = new Intent(getApplicationContext(), PlayService.class); intent.putExtra("key", 0); intent.putExtra("nkey", 0); startService(intent); String artistFirst = url.substring(url.lastIndexOf('/')+1, url.lastIndexOf('_')); String artistLast = url.substring(url.lastIndexOf('_')+1, url.lastIndexOf('-')); String song = url.substring(url.lastIndexOf('-')+1, url.lastIndexOf('.')); tv_artist.setText("Artist: "+artistFirst+" "+artistLast); tv_song.setText("Song: "+song); final ImageView album = (ImageView) findViewById(R.id.imageView1); album.setImageResource(R.drawable.album); } } }); </code></pre> <p>Is this a good way to approach this problem or should I pursue a more elegant solution? </p> <p>Edit::Solution found</p> <p>At start of the application I disable the play button and then enable it in my broadcastreceiver (which catches when the download finishes)</p> <pre><code> Button play = (Button) ((Activity) context).findViewById(R.id.play); play.setEnabled(true); </code></pre>
    singulars
    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.
 

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