0

When I click on this Widget radio should start playing and when I click it again radio should stop.

this my code ~!

private RemoteViews buildUpdate(Context context) {
            RemoteViews updateViews = new RemoteViews(context.getPackageName(),
                    R.layout.widget);   
     player =new MediaPlayer();
         try {
            player.setDataSource("http://94.102.55.40:8123");
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         player.prepareAsync();
         player.start();
     if(player.isPlaying()){
            player.stop();
        updateViews.setImageViewResource(R.id.phoneState,
                        R.drawable.on);
         }else{
        player.prepareAsync();
        player.start();
        updateViews.setImageViewResource(R.id.phoneState,
                        R.drawable.off);        
          }
    Intent i = new Intent(this, Appwidget.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
    updateViews.setOnClickPendingIntent(R.id.phoneState, pi);
    return updateViews;
}
Nur
  • 1
  • Check this link http://stackoverflow.com/q/4625547/840520 – Abhilasha Jul 24 '12 at 12:53
  • So, does your code work? Or it doesn't? If it doesn't - what's the problem? Be more specific! – Egor Jul 24 '12 at 12:54
  • The code doesnot work Problem that i want to make online radio work when i click on widget image When i click again i want to stop But my code doesnot do it – Nur Jul 24 '12 at 16:41

0 Answers0