Android. Stop flow from another flow



  • Audiopleer. The buttons are flooding and it's music. But how does this music stop another button?

    public class MainActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       Thread myThread;
    
        Button playButton = (Button) findViewById(R.id.play);
        Button stopButton = (Button) findViewById(R.id.stop);
    
        final Runnable runaudio =  new Runnable() {
            public void run() {
                MediaPlayer media = new MediaPlayer();
                media = MediaPlayer.create(MainActivity.this, R.raw.arena);
                media.start();}};
    
    
        playButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view){
    
                Thread myThread = new Thread(runaudio);
    
                myThread.start();
            }
        });
    
        stopButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view){
    
            }
        });
    
    }
    

    }



  • You don't have the right approach to writing a player first. Music losses must be made Service marked foreground() and the relevant notification, otherwise, in the absence of resources, your player will simply be brushed by the axle and the user will be indifferent.

    And what to say is that during the coming challenge or the other action, the player will lose all the time. If you turn on the standard player now and yours at the same time, they'll play at the same time.

    It shouldn't be like that.

    Use the service and the problem will fall.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2