Hi Piran/Bob,
I meant, I just needed a start and thanks to both of you to guide in a 
right direction.
I have started developing it. At first, I am creating a Service to run the 
music.
But need your help to clarify why it is not running for me (when I run it 
using activity alone, it plays the song).
 
Here is my main activity java file:
 
public class MainActivity extends Activity {
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }
 public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }
}
 
 
And below is another class MyService.java which essentially is a service:
 
public class MyService extends Service implements OnPreparedListener {
 private static final String ACTION_PLAY = "com.example.action.PLAY";
 MediaPlayer mMediaPlayer = null;
 Uri myUri=Uri.parse(getPackageResourcePath() + R.raw.shanti);
 public int onStartCommand(Intent intent, int flags, int startId) {
  if(intent.getAction().equals(ACTION_PLAY)){
   try {
    mMediaPlayer=new MediaPlayer();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setDataSource(getApplicationContext(), myUri);
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.prepareAsync();
   }catch(IOException e){
    mMediaPlayer=null;
   }
  }
  return 0;
 }
 public void onPrepared(MediaPlayer mMediaPlayer) {
  mMediaPlayer.start();
 }
 public IBinder onBind(Intent intent) {
  return null;
 }
}
 
In the Manifest file, I have included the service just by placing this code:
<service android:name="os.musicplay.MyService" />
 
When I am running it, nothing is happening !! 
Can you please advise whats going wrong here?
Appreciate your reply.
 
Peaceful Time Ahead...
 

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to