Further to my previous email, I have sketched out how my Media Player
will work with the actual MediaPlayer object in a separate service,
MediaService. I can't work out how to make calls, and retrieve data from
the service. Following tutorials online has lead me to this:

MyApp.java - top level Activity, in onCreate():
...
MediaConnection conn = new MediaConnection();
StateApp state = (StateApp) getApplicationContext();
bindService( new Intent(this,MediaService.class), conn,
Context.BIND_AUTO_CREATE);
state.setMediaConnection(conn);
...
MediaView.java - View for playing media files, in play button onClick():
...
StateApp state = (StateApp) context.getApplicationContext();
MediaConnection conn = state.getMediaConnection();
conn.start(mediaLocation);
...

MediaConnection implements ServiceConnection:
public class MediaConnection implements ServiceConnection, MediaInterface{

     private Binder service;

     public void start(String loc){
         MediaInterface i = (MediaInterface)service;
         i.start(loc);
     }
     public void onServiceDisconnected(ComponentName cn){
         Log.i("INFO", "Service unbound ");
     }
     public void onServiceConnected(ComponentName cn, IBinder b){
         service = (Binder)b;
         Log.i("INFO", "Service bound ");
     }
}

Which throws a NullPointerException at i.start(loc). Can anyone tell me
what I'm doing wrong?

--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to