Skip to content

Commit

Permalink
[maro/#18] feat : Timer seekBar 오류 && Splash 화면 Handler로 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
leesumin0526 committed May 6, 2024
1 parent 2267c18 commit fbdf6a3
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 229 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

82 changes: 56 additions & 26 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions UMC_6th/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
android:theme="@style/Theme.UMC_6th"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".SongActivity"
android:exported="true"/>

<activity
android:name=".MainActivity"
android:exported="false"/>
</application>

</manifest>
3 changes: 3 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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)
}
}
Expand Down
73 changes: 73 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ package com.example.umc_6th
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 com.example.umc_6th.databinding.ActivitySongBinding
import java.util.Timer

class SongActivity : AppCompatActivity() {

lateinit var binding : ActivitySongBinding
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

Expand All @@ -40,10 +47,35 @@ class SongActivity : AppCompatActivity() {
binding.songPauseIv.setOnClickListener {
setPlayerStatus(false)
}
}

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 startTimer() {
timer = Timer(song.playTime, song.isPlaying)
timer.start()
}

private fun setPlayer(song : Song) {
binding.songMusicTitleTv.text = intent.getStringExtra("title")!!
binding.songSingerNameTv.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.songProgressSb.progress = (song.second * 1000 / song.playTime)

setPlayerStatus(song.isPlaying)
}


fun setPlayerStatus (isPlaying : Boolean){
Expand All @@ -55,4 +87,45 @@ class SongActivity : AppCompatActivity() {
binding.songPauseIv.visibility = View.GONE
}
}

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.songProgressSb.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("Song", "쓰레드가 죽었습니다. ${e.message}")
}

}
}
}
5 changes: 4 additions & 1 deletion UMC_6th/app/src/main/java/com/example/umc_6th/song.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ package com.example.umc_6th

data class Song(
val title : String = "",
val singer : String = ""
val singer : String = "",
var second : Int = 0,
var playTime : Int = 60,
var isPlaying : Boolean = false
)
5 changes: 3 additions & 2 deletions UMC_6th/app/src/main/res/layout/activity_song.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<SeekBar
android:id="@+id/song_progress_sb"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_height="10dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
Expand All @@ -160,9 +160,10 @@
android:progressBackgroundTint="@color/song_player_bg"
android:progressTint="@color/song_player"
android:thumb="@color/transparent"
android:max="100000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/song_like_iv_layout"/>
app:layout_constraintTop_toBottomOf="@+id/song_like_iv_layout" />

<TextView
android:id="@+id/song_start_time_tv"
Expand Down

0 comments on commit fbdf6a3

Please sign in to comment.