투케이2K

401. (kotlin/코틀린) [유틸 파일] ringtonePlayStart : 모바일 링톤 알림음 재생 - RingtoneManager 본문

Kotlin

401. (kotlin/코틀린) [유틸 파일] ringtonePlayStart : 모바일 링톤 알림음 재생 - RingtoneManager

투케이2K 2023. 8. 28. 10:21
반응형

[개발 환경 설정]

개발 툴 : AndroidStudio

개발 언어 : Kotlin

 

[소스 코드]

 

        // ------------------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [모바일 링톤 알림음 재생 메소드]
        // ------------------------------------------------------------------------------------------
        var callRingtoneHandler: Handler = Handler(Looper.getMainLooper())
        fun ringtonePlayStart(mContext: Context) {

            /**
             * // -----------------------------------------
             * [ringtonePlayStart 메소드 설명]
             * // -----------------------------------------
             * 1. 모바일 링톤 알림음 재생 수행
             * // -----------------------------------------
             * 2. 호출 방법 : C_SoundPlay_Module.ringtonePlayStart(A_Intro@this)
             * // -----------------------------------------
             */


            // [로직 처리 실시]
            try {
                // ===============================================================
                S_Log._F_(mContext, "모바일 링톤 알림음 재생 수행", null)
                // ===============================================================

                Handler(Looper.getMainLooper()).postDelayed({

                    val defaultSoundUri = RingtoneManager.getActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_NOTIFICATION)

                    if (defaultSoundUri != null) {

                        val ringtone = RingtoneManager.getRingtone(mContext, defaultSoundUri)
                        if (callRingtoneHandler != null) {
                            callRingtoneHandler.postDelayed({ ringtone.stop() }, 2000) // [작업 예약]
                            ringtone.play() // [알림음 재생]
                        }

                    }

                }, 0)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }

 

반응형
Comments