AndroidTV IPTV chan...
 
Notifications
Clear all

Welcome to bestrestream iptv forum• İp Tv Forum • IPTV community • IPTV Forum Site

If email confirmation not received check spam box in your email.

  • Everyone is invited! My iptv forum is for everyone, new and advanced user alike!
  • Searching is key! Before you post a question, use the iptv forum search feature to determine whether your topic has already been covered.
  • Do not start flame wars! If someone has engaged in behavior that is detrimental to the discussion -- spamming, harassment, etc -- report the post and we'll take a look.
  • Join us now to access all our features. Once you register and login, you will be able to create topics, reply to existing topics, give reputation to your other members, get your own private messenger, and much more. It's also fast and completely free, so what are you waiting for?

AndroidTV IPTV change channel by number input

1 Posts
1 Users
0 Reactions
125 Views
SAMUEL
(@samuel)
Posts: 50
Estimable Member
Topic starter
 

Need to change channel by numpad of remote controller but don't know correct method. Numbers can be pressed multiple times and need to wait for all of them and get 1 String like "123".

Now I override onKey up like below

override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
    return when(keyCode){
        KeyEvent.KEYCODE_1->{
            //I don't know how to wait here next key up and get correct full channel number
            true

        }
        KeyEvent.KEYCODE_2->{
            ...
            true
        }
        //EPG
        KeyEvent.KEYCODE_3->{
            ...
            true
        }
        ...
        ...
        
        else -> super.onKeyUp(keyCode, event)
    }
}
 

1 Answer

 
 
 
  • To perform searching you need first to collect all digits of the number in range of some time, you can use StringBuilder to append one digit inside onKeyUp or OnKeyDown depend on your requirements

  • You need to delay performing search until the user write the full number, you can use CountDownTimer and reset the time every time the use write new digit (You can also create a progress bar represent the timer and update it) or you can use simple Timer

  • When the time is finish you should perform the search operation and clear the last number in StringBuilder and Update UI

val channelNumber = StringBuilder()
val numberSearchTimer : CountDownTimer?

override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
    return when(keyCode){
        KeyEvent.KEYCODE_1 -> {
            cannelNumber.append("1")
            perfomNumberSearch()
            true
        }
        KeyEvent.KEYCODE_2 -> {
            cannelNumber.append("2")
            perfomNumberSearch()
            true
        }
        ...
        
        else -> super.onKeyUp(keyCode, event)
    }
}

private fun perfomNumberSearch() {
    // Update UI With the new number
    binding.searchChannelNumber.text = channelNumber.toString()
    
    // Cancel the current time of it exists
    if (numberSearchTimer != null) numberSearchTimer.cancel()
    
    numberSearchTimer = object : CountDownTimer(1000, 100) {
        override fun onTick(millisUntilFinished: Long) {
             // Update UI With a progress until it perform search
             // or replace CountDownTimer with Timer
        }
        
        override fun onFinish() {
            changeChannelByNumber(channelNumber.toString())
            
            
            // Clear the last search number after performing it
            channelNumber.clear()
            binding.searchChannelNumber.text = channelNumber.toString()
        }
    }.start()
}
 
Posted : 08/07/2024 3:23 pm
Share:
Scroll to Top