package com.example.music

import android.media.MediaPlayer
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.music.ui.theme.MusicTheme
import java.util.concurrent.TimeUnit

class MainActivity : ComponentActivity() {

    override fun onCreate (savedInstanceState:Bundle?) {

        super.onCreate (savedInstanceState)
        setContentView (R.layout.activity_main)
    }

    override fun onResume () {
        super.onResume()
        try {
            val mp = MediaPlayer()
            mp.setDataSource ("http://philos.nmu.edu/polka/polka.mp3")
            mp.prepare()
            mp.start()
            try {
                TimeUnit.SECONDS.sleep (10)  //I sleep for ten seconds and then throw an exception
            } catch (e:Exception) {
            }
            mp.pause ()
            try {
                TimeUnit.SECONDS.sleep (5)
            } catch (e:Exception) {
            }
            mp.start ()
            try {
                TimeUnit.SECONDS.sleep (5)
            } catch (e:Exception) {
            }
            mp.reset()
            mp.setDataSource ("http://philos.nmu.edu/polka/polka.mp3")
            mp.prepare()
            mp.start()


        } catch (e:Exception) {
            e.printStackTrace()
        }

    }
}

