diff --git a/UMC_6th/app/src/main/AndroidManifest.xml b/UMC_6th/app/src/main/AndroidManifest.xml index fb79b9a..13cb508 100644 --- a/UMC_6th/app/src/main/AndroidManifest.xml +++ b/UMC_6th/app/src/main/AndroidManifest.xml @@ -14,7 +14,8 @@ tools:targetApi="31"> + android:exported="true" + android:theme="@style/SplashTheme"> diff --git a/UMC_6th/app/src/main/java/com/example/myfirstapp/MainActivity.kt b/UMC_6th/app/src/main/java/com/example/myfirstapp/MainActivity.kt index 42efede..52be5f3 100644 --- a/UMC_6th/app/src/main/java/com/example/myfirstapp/MainActivity.kt +++ b/UMC_6th/app/src/main/java/com/example/myfirstapp/MainActivity.kt @@ -4,12 +4,9 @@ import android.content.Intent import android.os.Bundle import android.util.Log import android.widget.Toast -import androidx.activity.enableEdgeToEdge import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity -import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsCompat import com.example.myfirstapp.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { @@ -19,13 +16,14 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + setTheme(R.style.Theme_MyApplication) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) setBottomNavigationView() //MainActivity에서 SongActivity로 데이터 값 넘기기 위한 변수명 지정 - val song = Song(binding.mainPlayTitleTv.text.toString(), binding.mainPlaySingerTv.text.toString()) + val song = Song(binding.mainPlayTitleTv.text.toString(), binding.mainPlaySingerTv.text.toString(),0,60,false) //SongActivity에서 Mainactivity로 데이터 넘긴거 받고 가수명과 노래 제목 toast로 출력 activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> @@ -43,6 +41,9 @@ class MainActivity : AppCompatActivity() { val intent = Intent(this, SongActivity::class.java) intent.putExtra("title", song.title) intent.putExtra("singer",song.singer) + intent.putExtra("second",song.second) + intent.putExtra("playTime",song.playTime) + intent.putExtra("isPlaying",song.isPlaying) activityResultLauncher.launch(intent) } diff --git a/UMC_6th/app/src/main/java/com/example/myfirstapp/Song.kt b/UMC_6th/app/src/main/java/com/example/myfirstapp/Song.kt index c00f378..24d1288 100644 --- a/UMC_6th/app/src/main/java/com/example/myfirstapp/Song.kt +++ b/UMC_6th/app/src/main/java/com/example/myfirstapp/Song.kt @@ -1,6 +1,9 @@ package com.example.myfirstapp data class Song( - val title : String = "", - val singer : String = "" + val title: String = "", + val singer: String = "", + var second: Int = 0, + var playTime: Int = 0, + var isPlaying: Boolean = false ) diff --git a/UMC_6th/app/src/main/java/com/example/myfirstapp/SongActivity.kt b/UMC_6th/app/src/main/java/com/example/myfirstapp/SongActivity.kt index cfcb319..7268984 100644 --- a/UMC_6th/app/src/main/java/com/example/myfirstapp/SongActivity.kt +++ b/UMC_6th/app/src/main/java/com/example/myfirstapp/SongActivity.kt @@ -2,32 +2,34 @@ package com.example.myfirstapp import android.content.Intent import android.os.Bundle -import android.os.PersistableBundle +import android.util.Log import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat -import com.example.myfirstapp.databinding.ActivityMainBinding import com.example.myfirstapp.databinding.ActivitySongBinding class SongActivity : AppCompatActivity() { lateinit var binding: ActivitySongBinding private var isColorChanged = false + lateinit var song : Song + lateinit var timer: Timer override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivitySongBinding.inflate(layoutInflater) setContentView(binding.root) + initSong() + setPlayer(song) + var title : String? = null var singer : String? = null //MainActivity에서 SongActivity로 넘긴 데이터 값 받는 곳 - if(intent.hasExtra("title") && intent.hasExtra("singer")){ - title = intent.getStringExtra("title") - singer = intent.getStringExtra("singer") - binding.songMusicTitleTv.text = title - binding.songMusicSingerTv.text = singer + if(intent.hasExtra("title")&&intent.hasExtra("singer")){ + binding.songMusicTitleTv.text = intent.getStringExtra("title") + binding.songMusicSingerTv.text = intent.getStringExtra("singer") } //SongActivity에서 Mainactivity로 데이터 넘기는 곳 @@ -45,10 +47,6 @@ class SongActivity : AppCompatActivity() { binding.songMiniplayerPauseIv.setOnClickListener{ setPlayerStatus(true) } - if(intent.hasExtra("title")&&intent.hasExtra("singer")){ - binding.songMusicTitleTv.text = intent.getStringExtra("title") - binding.songMusicSingerTv.text = intent.getStringExtra("singer") - } binding.songRepeatIv.setOnClickListener { if (isColorChanged) { @@ -71,6 +69,32 @@ class SongActivity : AppCompatActivity() { } } + override fun onDestroy() { + super.onDestroy() + timer.interrupt() + } + private fun initSong() { + if(intent.hasExtra("title") && intent.hasExtra("singer")) { + song = Song( + intent.getStringExtra("title")!!, + intent.getStringExtra("singer")!!, + intent.getIntExtra("second", 0), + intent.getIntExtra("playTime", 0), + intent.getBooleanExtra("isPlaying", false) + ) + } + startTimer() + } + private fun setPlayer(song: Song){ + binding.songMusicTitleTv.text = intent.getStringExtra("title") + binding.songMusicSingerTv.text = intent.getStringExtra("singer") + binding.songStartTimeTv.text = String.format("%02d:%02d",song.second / 60, song.second % 60) + binding.songEndTimeTv.text = String.format("%02d:%02d",song.playTime / 60, song.playTime % 60) + binding.songSeekbarSb.progress = (song.second *1000 /song.playTime) + + setPlayerStatus(song.isPlaying) + } + // override fun onBackPressed() { // super.onBackPressed() // val intent = Intent(this, MainActivity::class.java) @@ -80,6 +104,8 @@ class SongActivity : AppCompatActivity() { // } fun setPlayerStatus(isPlaying : Boolean){ + song.isPlaying = isPlaying + timer.isPlaying = isPlaying if(isPlaying){ //재생중 binding.songMiniplayerPlayIv.visibility = View.VISIBLE binding.songMiniplayerPauseIv.visibility = View.GONE @@ -89,4 +115,42 @@ class SongActivity : AppCompatActivity() { binding.songMiniplayerPauseIv.visibility = View.VISIBLE } } + + private fun startTimer() { + timer = Timer(song.playTime, song.isPlaying) + timer.start() + } + inner class Timer(private val playTime: Int, var isPlaying: Boolean = true):Thread(){ + private var second : Int = 0 + private var mills: Float = 0f + + override fun run() { + super.run() + try{ + while(true){ + if(second >= playTime){ + break + } + if(isPlaying){ + sleep(50) + mills += 50 + + runOnUiThread { + binding.songSeekbarSb.progress = ((mills / playTime)*100).toInt() + } + if(mills % 1000 == 0f){ + runOnUiThread { + binding.songStartTimeTv.text = String.format("%02d:%02d",second / 60, second % 60) + } + second++ + } + } + } + }catch(e: InterruptedException){ + Log.d("SongActivity","쓰레드가 죽었습니다") + } + + } + + } } \ No newline at end of file diff --git a/UMC_6th/app/src/main/res/layout/activity_song.xml b/UMC_6th/app/src/main/res/layout/activity_song.xml index a4d47c4..b64d960 100644 --- a/UMC_6th/app/src/main/res/layout/activity_song.xml +++ b/UMC_6th/app/src/main/res/layout/activity_song.xml @@ -148,6 +148,9 @@ android:layout_marginStart="20dp" android:layout_marginEnd="20dp" android:layout_marginTop="10dp" + android:background="@null" + android:paddingStart="0dp" + android:paddingEnd="0dp" android:progressTint="@color/song_player" android:progressBackgroundTint="@color/song_player_bg" android:progress="0" @@ -198,13 +201,13 @@ android:src="@drawable/btn_miniplayer_previous"/> \ No newline at end of file