如何制作在线广播小工具

时间:2012-07-24 12:48:03

标签: android android-widget

当我点击这个Widget收音机应该开始播放时,当我再次点击它时,收音机应该停止。

这是我的代码〜!

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;
}

0 个答案:

没有答案