前提・実現したいこと
はじめてのAndroidプログラミング 第4版
Chapter9:カウントダウンタイマーでUnresolved reference: playStopが
解決できず困っています。
発生している問題・エラーメッセージ
Unresolved reference: playStop Unresolved reference: playStop Unresolved reference: playStop
該当のソースコード
<Android StudioでKotlinを使っています>
package com.example.kenta.mycountdowntimer
import android.content.IntentSender
import android.media.AudioManager
import android.media.SoundPool
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import com.example.kenta.mycountdowntimer.MainActivity.MyCountDownTimer
import kotlinx.android.synthetic.main.activity_main.*
import java.util.concurrent.CompletableFuture
class MainActivity : AppCompatActivity() {
private lateinit var soundPool: SoundPool private var soundResId = 0 inner class MyCountDownTimer( millisInFuture: Long, countDownInterval: Long ) : CountDownTimer(millisInFuture, countDownInterval) { var isRunning = false override fun onTick(millisUntilFinished: Long) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. val minute = millisUntilFinished / 1000L / 60L val second = millisUntilFinished / 1000L % 60L timerText.text = "%1d:%2$02d".format(minute, second) } override fun onFinish() { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. timerText.text = "0:00" soundPool.play(soundResId, 1.0f, 100f, 0, 0, 1.0f) } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) timerText.text = "3:00" val timer = MyCountDownTimer(3 * 60 * 1000, 100) playStop.setOnClickListener { timer.isRunning = when (timer.isRunning) { true -> { timer.cancel() playStop.setImageResource( R.drawable.ic_play_arrow_black_24dp ) false } false -> { timer.start() playStop.setImageResource( R.drawable.ic_play_arrow_black_24dp ) true } } } } override fun onResume() { super.onResume() soundPool = SoundPool(2, AudioManager.STREAM_ALARM, 0) soundResId = soundPool.load(this, R.raw.bellsound, 1) } override fun onPause() { super.onPause() soundPool.release() }
}
### 試したこと ネットで複数Unresolved referenceの解決方法について調べましたが解決できずでした。 初心者のため、深く理解できていない可能性は高いです。 ### 補足情報(FW/ツールのバージョンなど) Mac版 AndroidStudio3.4を利用しております。 他に必要な情報などあればお教えいただければ調べて記載いたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/04 13:59 編集
2019/05/05 00:00