How to make an audio palyer widget in android -


i want make audio player widget in have added there buttons play , next , previous.widget should show title progress of song on seek bar , image if available same.

i unable find how can play songs ,can go previous or next song , how show progress on seek bar through audio widget.

following appwidgetprovider class have created this.

public class audiomusicwidgetprovider extends appwidgetprovider {     public static string action_widget_receiver = "playactionreceiverwidget";     textview songtitle;     arraylist<song>arraylist;     @override     public void onupdate(context context, appwidgetmanager appwidgetmanager, int[] appwidgetids) {         // todo auto-generated method stub          remoteviews remoteviews = new remoteviews(context.getpackagename(),                 r.layout.musicplayerwidget);          toast.maketext(context, "onupdate", toast.length_short).show();          getsongslist(context);          intent action = new intent(context, audiomusicwidgetprovider.class);         action.setaction(action_widget_receiver);         action.putextra("msg", "this starts playing");         pendingintent actionpendingintent = pendingintent.getbroadcast(context,                 0, action, 0);         remoteviews.settextviewtext(r.id.songtitle,"");         remoteviews.setonclickpendingintent(r.id.btnplay,                 actionpendingintent);         remoteviews.setonclickpendingintent(r.id.btnnext,                 actionpendingintent);         remoteviews.setonclickpendingintent(r.id.btnprevious, actionpendingintent);         appwidgetmanager.updateappwidget(appwidgetids, remoteviews);         super.onupdate(context, appwidgetmanager, appwidgetids);     }       @override     public void onreceive(context context, intent intent) {         // v1.5 fix doesn't call ondelete action         final string action = intent.getaction();         if (appwidgetmanager.action_appwidget_deleted.equals(action)) {             //the widget being deleted off desktop             final int appwidgetid = intent.getextras().getint(                     appwidgetmanager.extra_appwidget_id,                     appwidgetmanager.invalid_appwidget_id);             if (appwidgetid != appwidgetmanager.invalid_appwidget_id) {                 this.ondeleted(context, new int[]{appwidgetid});             }         } else {             // check, if our action called             if (intent.getaction().equals(action_widget_receiver)) {                  //play audio file                 //the audio file in /res/raw/ , ogg file                playaudio(arraylist.get(0).getpath());             } else {                 // nothing             }               super.onreceive(context, intent);         }     }       public  void getsongslist(context context){         arraylist = new arraylist<>();         contentresolver contentresolver = context.getcontentresolver();         uri songuri = mediastore.audio.media.external_content_uri;         cursor songcursor = contentresolver.query(songuri, null, null, null, null);          if(songcursor != null && songcursor.movetofirst()){               song song = new song();              int songid =songcursor.getcolumnindex(mediastore.audio.media._id);              int songtitle = songcursor.getcolumnindex(mediastore.audio.media.title);             int artist = songcursor.getcolumnindex(mediastore.audio.media.artist);             int duration = songcursor.getcolumnindexorthrow(mediastore.audio.media.duration);             {                 song.setsongid((int) songcursor.getlong(songid));                 song.settitle(songcursor.getstring(songtitle));                 song.setsinger(songcursor.getstring(artist));                 song.setduration(songcursor.getstring(duration));                 song.setpath(songcursor.getstring(songcursor.getcolumnindex(mediastore.audio.media.data)));                 arraylist.add(song);             }while(songcursor.movetonext());         }      }       public static void playaudio(final string path) {         final mediaplayer player = new mediaplayer();         if (path == null) {            // log.e(logging_tag, "called playaudio null data stream.");             return;         }         try {             player.setdatasource(path);             player.prepare();             player.start();         } catch (exception e) {           //  log.e(logging_tag, "failed start mediaplayer: " + e.getmessage());             return;         }     } } 

how can implement please.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -