简体   繁体   English

Android,隐藏视频而不停止音频播放

[英]Android, hide video without stopping audio playback

(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. 我正在尝试使用TextureView显示视频,但是我需要知道是否有一种隐藏视频而不停止音频播放的方法。

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. 您可以看到我正在尝试使用setSurface(null),但是尝试此操作时音频不会保留。

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 我需要在按下“后退”按钮或“主页”按钮时保持音频播放

将您的TextureView的可见性设置为INVISIBLE

mTextureView.setVisibility(View.INVISIBLE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM