package com.example.ghomi.chapter6_1;

import android.app.IntentService;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Handler;

public class MyIntentService extends IntentService {
    long seconds;
    Handler mHandler;
    MediaPlayer mp;

    public MyIntentService() {
        super("MyIntentService");
        mHandler = new Handler();
    }
  @Override
  protected void onHandleIntent(Intent intent) {
        seconds =intent.getExtras().getLong("seconds");
        mHandler.post(new DisplayToast(this, "Service Started, wait..."));
        long millis = seconds * 1000;

        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        mp = MediaPlayer.create(getApplicationContext(), R.raw.mysong);
        mp.start();
        mHandler.post(new DisplayToast(this, "Playing started"));
    }
}
