반응형
package com.example.sound
import android.media.SoundPool
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val mPlay = SoundPool.Builder().build()
val SD = mPlay.load(this, R.raw.army, 1)
val btn = findViewById<Button>(R.id.button)
btn.setOnClickListener {
mPlay.play(SD, 1.0f, 1.0f, 0, 0, 1.0f)
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PLAY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
반응형
'kotlin↗ > 안드로이드 스튜디오 메이킹' 카테고리의 다른 글
[KOTLIN] 컬러 변경 및 컬러 색상 추가하기 (0) | 2024.02.07 |
---|---|
[KOTLIN] Dialog에 날짜 선택 만드는 코드 (0) | 2024.02.07 |
[KOTLIN] 다이얼로그 Dialog 생성 (0) | 2024.02.07 |
[KOTLIN] Firebase 어플 실행 시 Splash 화면에서 비회원 로그인 받아주기 (0) | 2024.02.07 |
[KOTLIN] FIREBASE 파이어베이스 익명 로그인 (1) | 2024.02.06 |