在播放视频时的活动被隐藏 [英] Playing video when activity is hidden

查看:143
本文介绍了在播放视频时的活动被隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这方面的一个例子是最容易想到的潘多拉的Andr​​oid的理解。

An example of this is most easily understood by thinking of "Pandora for Android".

我的活动都有一个VideoView从一个类打讲座。 我希望能够通过这次活动不间断地切换到另一个活动(在我的应用程序,或到不同的应用程序(主屏幕,其他一些应用程序))。

My activity has a VideoView playing lectures from a class. I would like to be able to switch from this Activity to another activity (In my application, or to a different application (home screen, some other app) ) without interruption.

使用,同时播放音乐,我可以去到主屏幕,并继续浏览手机上无缝潘多拉的例子,我可以去'开关电台的观点。

Using the Pandora example I could go to the 'switch radio stations' view while playing music and I could go to the home screen and continue navigating on the phone seamlessly.

这是仅适用于视频或音频?我可以只从一个视频文件播放音频,然后切换回容易吗?

Is this possible for videos, or audio only? Can I just play the audio from a video file and then switch back easily?

推荐答案

这是处理的一般方法(和Pandora如何​​处理它)是从在后台线程服务播放音乐。 VideoView不能在这种情况下使用,因为它是一个视图,并绑定到一个活动。

The general way this is handled (and how Pandora handles it) is to playback the music from a service on a background thread. VideoView can't be used in this case as it's a View and is tied to an activity.

我会通过启动了Android <一接近这个href="http://www.google.com/$c$csearch#cZwlSNS7aEw/frameworks/base/core/java/android/widget/VideoView.java&exact_package=android&q=videoview&type=cs"相对=nofollow> VideoView code和分割在两个,一个部分来处理用户界面和其他的视频播放。

I would approach this by starting with the Android VideoView code and splitting it in two, one part to handle the UI and the other for video playback.

运行中的MediaPlayer后台服务和视频活动时显示,有服务电话MediaPlayer.setDisplay()与您的视频观看表面,并调用MediaPlayer.setDisplay()与空时,视频的看法是隐藏的。

Run the MediaPlayer in a background service and when your video activity is shown, have the service call MediaPlayer.setDisplay() with your video view surface, and call MediaPlayer.setDisplay() with null when your video view is hidden.

显然,这不仅仅是直接使用VideoView更加复杂,需要启动的服务和协调,与UI。你也很可能逃脱刚刚运行的MediaPlayer在后台线程,而不是服务。

Obviously this is much more complex than just using VideoView directly and requires starting a service and coordinating that with the UI. You could also probably get away with just running the MediaPlayer in a background thread and not a service.

这篇关于在播放视频时的活动被隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆