Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maro/#18] feat :: 4주차 구현 #19

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

51 changes: 43 additions & 8 deletions .idea/workspace.xml

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

5 changes: 3 additions & 2 deletions UMC_6th/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true"
android:theme="@style/SplashTheme">
<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"/>
Expand Down
4 changes: 4 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 @@ -16,6 +16,7 @@ class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.SplashTheme)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

Expand All @@ -42,6 +43,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
76 changes: 76 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,13 +47,41 @@ 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){
song.isPlaying = isPlaying
timer.isPlaying = isPlaying

if(isPlaying){ // 재생중
binding.songMiniplayerIv.visibility = View.GONE
binding.songPauseIv.visibility = View.VISIBLE
Expand All @@ -55,4 +90,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
)
4 changes: 3 additions & 1 deletion UMC_6th/app/src/main/res/drawable/splash.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/white"/>
<item>
<bitmap android:src="@drawable/ic_flo_logo" android:gravity="center"/>
<bitmap
android:src="@drawable/ic_flo_logo"
android:gravity="center"/>
</item>

</layer-list>
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
5 changes: 4 additions & 1 deletion UMC_6th/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground"> @drawable/splash </item>
<item name="android:statusBarColor">@color/transparent </item>
</style>
<style name="Theme.UMC_6th" parent="Base.Theme.UMC_6th" />
</resources>