0

(Sorry for my english)

I 'm trying to show video using TextureView, but I need to know if there is a way to hide the video without stopping audio playback.

Thus I am doing:

public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        mySurface = new Surface(surface);
        if(MyService.mMediaPlayer != null) MyService.mMediaPlayer.setSurface(mySurface);
    }

@Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        if(MyService.mMediaPlayer != null) MyService.mMediaPlayer.setSurface(null);
        return false;
    }

You can see that I'm trying using setSurface(null) but the audio does not remain when I try this.

EDIT: I have a button in my main activity ( "show video") ; this button starts the second activity where I put the above code .

I need the audio keeps playing when I press the Back button or the home button

Arnaldo
  • 673
  • 6
  • 22

1 Answers1

0

Set the visibility of your TextureView to INVISIBLE

mTextureView.setVisibility(View.INVISIBLE);
Chris Stillwell
  • 10,266
  • 10
  • 67
  • 77
  • Thank You @ChrisStillwell, but how should I do if I have on another activity? – Arnaldo Oct 05 '15 at 21:47
  • There are a number of ways and it all depends on where you would need to call that Activity from. The best I can think of is to create a method in your Activity then call that method where you need to. – Chris Stillwell Oct 05 '15 at 21:51
  • I have added more information about what I want to do. – Arnaldo Oct 05 '15 at 22:04
  • Ok, that changes things a lot. You'll need a service then. See if this will help you: http://stackoverflow.com/questions/16336960/android-playing-music-in-background – Chris Stillwell Oct 06 '15 at 14:12
  • Yes, I am currently working with Media Player with Service and everything works fine except that I can not release the video and leave only audio playing, I 'm using: `MyService.mMediaPlayer.setSurface(mySurface);` and I still have the same question. – Arnaldo Oct 06 '15 at 19:24