1. Are you ready for the Galaxy S20? Here is everything we know so far!

Need help with foreground service

Discussion in 'Android Development' started by jamaljackson, Jan 7, 2021.

  1. jamaljackson

    jamaljackson Lurker
    Thread Starter

    Can anyone please help me. Completely new to Android development, am currently using Kotlin. I made my very first online streaming media app, but whenever i change apps, or turn off the screen, the audio stops. I've tried looking through the Android docs, but i can't understand it. Can anyone please help me!


    Code (Java):
    1. package com.example.al_bunyan
    2.  
    3. import android.app.Dialog
    4. import android.content.Intent
    5. import android.graphics.Color
    6. import android.graphics.drawable.AnimationDrawable
    7. import android.media.MediaPlayer
    8. import android.net.Uri
    9. import androidx.appcompat.app.AppCompatActivity
    10. import android.os.Bundle
    11. import android.view.View
    12. import android.widget.Button
    13. import android.widget.ImageView
    14. import android.widget.RelativeLayout
    15. import android.widget.VideoView
    16. import java.time.Instant
    17.  
    18. class MainActivity : AppCompatActivity() {
    19.  
    20.     override fun onCreate(savedInstanceState: Bundle?) {
    21.         super.onCreate(savedInstanceState)
    22.         setContentView(R.layout.activity_main)
    23.  
    24.  
    25.         var web_btn = findViewById<Button>(R.id.link_btn)
    26.  
    27.  
    28.  
    29.         web_btn.setOnClickListener {
    30.  
    31.  
    32.             var intent = Intent(this@MainActivity, AlbunyaWebview::class.java)
    33.             startActivity(intent)
    34.         }
    35.      
    36.  
    37.     }
    38.  
    39.     fun video_check(view:View) {
    40.  
    41.         val fm105 = findViewById<Button>(R.id.fm105_7)
    42.         val alert = Dialog(this@MainActivity)
    43.         alert.setContentView(R.layout.audio_play)
    44.         val video = alert.findViewById<VideoView>(R.id.video_alert)
    45.         val play = alert.findViewById<Button>(R.id.play)
    46.         val pause = alert.findViewById<Button>(R.id.pause)
    47.         val resume = alert.findViewById<Button>(R.id.resume)
    48.  
    49.  
    50.  
    51.         if (fm105.isPressed) {
    52.  
    53.             val video_1 = Uri.parse("http://albunyan.fm:8000/live")
    54.             video.setVideoURI(video_1)
    55.  
    56.             alert.show()
    57.  
    58.             play.setOnClickListener {
    59.  
    60.                 video.start()
    61.             }
    62.  
    63.             pause.setOnClickListener {
    64.  
    65.                 video.pause()
    66.             }
    67.  
    68.             resume.setOnClickListener {
    69.  
    70.                 video.start()
    71.             }
    72.  
    73.         }
    74.     }
    75.  
    76. }
     


    #1 jamaljackson, Jan 7, 2021
    Last edited by a moderator: Jan 7, 2021

    1. Download the Forums for Android™ app!


      Download

       
  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator

    I moved your thread to the development area. I also added code tags so your syntax is easier to read. Good luck!!:)

    Code Tags Usage:
    [code]Line 1
    Line 2
    Line 3
    [/code]

    Result:
    Code (Text):
    1. Line 1
    2. Line 2
    3. Line 3
    4.  
     
  3. jamaljackson

    jamaljackson Lurker
    Thread Starter

    Thank you so much bro. Really appreciate your help
     
    Unforgiven likes this.
Loading...

Share This Page

Loading...