供应选项用户带或不带音频播放视频 [英] Supplying option to user to play video with or without audio

查看:153
本文介绍了供应选项用户带或不带音频播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VideoView发挥mp4视频。我想给用户观看该视频与声音的选项或静音,如果他/她选择。我不使用的MediaController允许用户停止和播放,我有触摸事件控制这一点。

I am using VideoView to play an mp4 video. I would like to give the user the option of watching this video with sound or mute the sound if he/she chooses. I do not use the mediaController allowing the user to stop and play, I have "touch" events controlling this.

更新:我有我添加了一个静音图标的菜单。现在,我试图找出如何静音添加到该按钮。我读从Android AudioManager一些信息,特别是setStreamMute。下面是该API的说:

UPDATE: I have a menu that I have added a "mute" icon to. Now I am trying to figure out how to add the mute to this button. I am reading some info on from the Android AudioManager, in particular the setStreamMute. Here is what the API's say:

  public void  setStreamMute  (int streamType, boolean state)

自:API级别1

Since: API Level 1

静音或取消静音音频流。

Mute or unmute an audio stream.

静音命令进行保护,防止客户端进程死亡:如果有一个流上的主动静音请求的进程死亡,这个流将被自动取消静音

The mute command is protected against client process death: if a process with an active mute request on a stream dies, this stream will be unmuted automatically.

有一个给定的流中的静音请求是累积:所述AudioManager可以从一个或多个客户接收若干静音请求和接收取消静音请求相同数量的,只有当流将被取消静音

The mute requests for a given stream are cumulative: the AudioManager can receive several mute requests from one or more clients and the stream will be unmuted only when the same number of unmute requests are received.

对于一个更好的用户体验,应用程序必须在静音的onPause(静音流),并再次静音是onResume(),如果合适的话。

For a better user experience, applications MUST unmute a muted stream in onPause() and mute is again in onResume() if appropriate.

此方法仅用于那些代替音频设置或主电话应用的平台级管理应用程序。 参数 streamType流进行静音/取消静音。 状态所需的静音状​​态:真正的静音ON,false为静音关闭

This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application. Parameters streamType The stream to be muted/unmuted. state The required mute state: true for mute ON, false for mute OFF

推荐答案

使用的AudioManager服务静音或取消静音只与您的视频流。从方式(S)已宣布响应用户触摸事件,就像调用方法:

Use the AudioManager service to mute and unmute just the stream related to your video. From the method(s) you have declared to respond to the user touch events, call methods like:

public void mute() {
  AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
  am.setStreamMute(AudioManager.STREAM_MUSIC, true);
}

public void unmute() {
  AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
  am.setStreamMute(AudioManager.STREAM_MUSIC, false);
}

这将使其他流(通知,报警等)活动的,所以你不能沉默,整个设备只是视频静音。

This will leave the other streams (notification, alarm, etc.) active so you aren't silencing the whole device just to mute the video.

另外,如果你需要建议你的活动而流应该推动音频通过您可以拨打 Activity.setVolumeControlStream(AudioManager.STREAM_MUSIC)来配合你的活动的窗口,该流。

Also, if you need to suggest to your Activity which stream it should be pushing the audio through you can call Activity.setVolumeControlStream(AudioManager.STREAM_MUSIC) to tie your Activity's window to that stream.

这篇关于供应选项用户带或不带音频播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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