- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在一些问题的帮助下,我设法使用 onTouchEvent
为我的视频播放器添加了音量和亮度控制。方法。但是当我向上或向下滑动我的应用程序时(它重新启动)。对我的代码有任何帮助,为什么无法使用 onTouchEvent 控制音量和亮度。
这是我的代码:
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
tested_ok=false;
if (event.getX() < (sWidth / 2)) {
intLeft = true;
intRight = false;
} else if (event.getX() > (sWidth / 2)) {
intLeft = false;
intRight = true;
}
int upperLimit = (sHeight / 4) + 100;
int lowerLimit = ((sHeight / 4) * 3) - 150;
if (event.getY() < upperLimit) {
intBottom = false;
intTop = true;
} else if (event.getY() > lowerLimit) {
intBottom = true;
intTop = false;
} else {
intBottom = false;
intTop = false;
}
seekSpeed = (TimeUnit.MILLISECONDS.toSeconds(exoPlayer.getDuration()) * 0.1);
diffX = 0;
calculatedTime = 0;
seekDur = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(diffX) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(diffX)),
TimeUnit.MILLISECONDS.toSeconds(diffX) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(diffX)));
//TOUCH STARTED
baseX = event.getX();
baseY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
screen_swipe_move=true;
root.setVisibility(View.GONE);
diffX = (long) (Math.ceil(event.getX() - baseX));
diffY = (long) Math.ceil(event.getY() - baseY);
double brightnessSpeed = 0.05;
if (Math.abs(diffY) > MIN_DISTANCE) {
tested_ok = true;
}
if (Math.abs(diffY) > Math.abs(diffX)) {
if (intLeft) {
cResolver = getContentResolver();
window = getWindow();
try {
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
brightness = Settings.System.getInt(cResolver, Settings.System.SCREEN_BRIGHTNESS);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
int new_brightness = (int) (brightness - (diffY * brightnessSpeed));
if (new_brightness > 250) {
new_brightness = 250;
} else if (new_brightness < 1) {
new_brightness = 1;
}
double brightPerc = Math.ceil((((double) new_brightness / (double) 250) * (double) 100));
brightnessBarContainer.setVisibility(View.VISIBLE);
brightness_center_text.setVisibility(View.VISIBLE);
brightnessBar.setProgress((int) brightPerc);
brigtness_perc_center_text.setText(" " + (int) brightPerc);
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, (new_brightness));
WindowManager.LayoutParams layoutpars = window.getAttributes();
layoutpars.screenBrightness = brightness / (float) 255;
window.setAttributes(layoutpars);
}else if (intRight) {
vol_center_text.setVisibility(View.VISIBLE);
mediavolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int maxVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
double cal = (double) diffY * ((double)maxVol/(double)(device_height*4));
int newMediaVolume = mediavolume - (int) cal;
if (newMediaVolume > maxVol) {
newMediaVolume = maxVol;
} else if (newMediaVolume < 1) {
newMediaVolume = 0;
}
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, newMediaVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
double volPerc = Math.ceil((((double) newMediaVolume / (double) maxVol) * (double) 100));
vol_perc_center_text.setText(" " + (int) volPerc);
volumeBarContainer.setVisibility(View.VISIBLE);
volumeBar.setProgress((int) volPerc);
}
}else if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > (MIN_DISTANCE + 100)) {
}
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
screen_swipe_move=false;
tested_ok = false;
seekBar_center_text.setVisibility(View.GONE);
brightness_center_text.setVisibility(View.GONE);
vol_center_text.setVisibility(View.GONE);
brightnessBarContainer.setVisibility(View.GONE);
volumeBarContainer.setVisibility(View.GONE);
onlySeekbar.setVisibility(View.VISIBLE);
root.setVisibility(View.VISIBLE);
calculatedTime = (int) (exoPlayer.getCurrentPosition() + (calculatedTime));
exoPlayer.seekTo(calculatedTime);
break;
}
return super.onTouchEvent(event);
}
VideoPlayerActivity.java
的完整代码
package com.sanoj.jlplayer.Activities;
public class VideoPlayerActivity extends AppCompatActivity {
Uri videoUri;
@BindView(R.id.playerView) PlayerView playerView;
@BindView(R.id.floating_widget) ImageView imageView;
@BindView(R.id.exoFullscreenIcon) ImageView imageView1;
@BindView(R.id.vol_perc_center_text) TextView vol_perc_center_text;
@BindView(R.id.brigtness_perc_center_text) TextView brigtness_perc_center_text;
@BindView(R.id.volume_slider) ProgressBar volumeBar;
@BindView(R.id.brightness_slider) ProgressBar brightnessBar;
@BindView(R.id.volume_slider_container) LinearLayout volumeBarContainer;
@BindView(R.id.brightness_slider_container) LinearLayout brightnessBarContainer;
@BindView(R.id.brightness_center_text) LinearLayout brightness_center_text;
@BindView(R.id.vol_center_text) LinearLayout vol_center_text;
@BindView(R.id.volIcon) ImageView volIcon;
@BindView(R.id.brightnessIcon) ImageView brightnessIcon;
@BindView(R.id.vol_image) ImageView vol_image;
@BindView(R.id.brightness_image) ImageView brightness_image;
boolean fullscreen = false;
ExoPlayer exoPlayer;
ExtractorsFactory extractorsFactory;
int sWidth,sHeight;
float baseX, baseY;
long diffX, diffY;
int calculatedTime;
String seekDur;
Boolean tested_ok = false;
Boolean screen_swipe_move = false;
boolean immersiveMode, intLeft, intRight, intTop, intBottom, finLeft, finRight, finTop, finBottom;
static final int MIN_DISTANCE = 150;
ContentResolver cResolver;
Window window;
TextView txt_seek_secs,txt_seek_currTime;
int brightness, mediavolume,device_height,device_width;
AudioManager audioManager;
double seekSpeed = 0;
LinearLayout root, seekBar_center_text, onlySeekbar;
Point size;
Display display;
SeekBar seekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
ButterKnife.bind(this);
Intent intent = getIntent();
//audio and brightness
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
display = getWindowManager().getDefaultDisplay();
size = new Point();
display.getSize(size);
sWidth = size.x;
sHeight = size.y;
if (intent!=null){
String uri_str = intent.getStringExtra("videoUri");
videoUri = Uri.parse(uri_str);
}
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
exoPlayer.setPlayWhenReady(false);
exoPlayer.release();
Intent serviceIntent = new Intent(VideoPlayerActivity.this,FloatingWidgetService.class);
serviceIntent.putExtra("videoUri",videoUri.toString());
startService(serviceIntent);
}
});
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
exoPlayer = ExoPlayerFactory.newSimpleInstance(this,trackSelector);
extractorsFactory = new DefaultExtractorsFactory();
playVideo();
}
private void playVideo() {
try {
String playerInfo = Util.getUserAgent(this,"VideoPlayer");
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this,playerInfo);
MediaSource mediaSource = new ExtractorMediaSource(videoUri,dataSourceFactory,extractorsFactory,null,null);
playerView.setPlayer(exoPlayer);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);
}catch (Exception e){
e.printStackTrace();
}
}
@Override
protected void onPause() {
super.onPause();
exoPlayer.setPlayWhenReady(false);
}
@Override
public void onBackPressed() {
super.onBackPressed();
exoPlayer.setPlayWhenReady(false);
exoPlayer.release();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
tested_ok=false;
if (event.getX() < (sWidth / 2)) {
intLeft = true;
intRight = false;
} else if (event.getX() > (sWidth / 2)) {
intLeft = false;
intRight = true;
}
int upperLimit = (sHeight / 4) + 100;
int lowerLimit = ((sHeight / 4) * 3) - 150;
if (event.getY() < upperLimit) {
intBottom = false;
intTop = true;
} else if (event.getY() > lowerLimit) {
intBottom = true;
intTop = false;
} else {
intBottom = false;
intTop = false;
}
seekSpeed = (TimeUnit.MILLISECONDS.toSeconds(exoPlayer.getDuration()) * 0.1);
diffX = 0;
calculatedTime = 0;
seekDur = String.format("%02d:%02d",
TimeUnit.MILLISECONDS.toMinutes(diffX) -
TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(diffX)),
TimeUnit.MILLISECONDS.toSeconds(diffX) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(diffX)));
//TOUCH STARTED
baseX = event.getX();
baseY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
screen_swipe_move=true;
root.setVisibility(View.GONE);
diffX = (long) (Math.ceil(event.getX() - baseX));
diffY = (long) Math.ceil(event.getY() - baseY);
double brightnessSpeed = 0.05;
if (Math.abs(diffY) > MIN_DISTANCE) {
tested_ok = true;
}
if (Math.abs(diffY) > Math.abs(diffX)) {
if (intLeft) {
cResolver = getContentResolver();
window = getWindow();
try {
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
brightness = Settings.System.getInt(cResolver, Settings.System.SCREEN_BRIGHTNESS);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
int new_brightness = (int) (brightness - (diffY * brightnessSpeed));
if (new_brightness > 250) {
new_brightness = 250;
} else if (new_brightness < 1) {
new_brightness = 1;
}
double brightPerc = Math.ceil((((double) new_brightness / (double) 250) * (double) 100));
brightnessBarContainer.setVisibility(View.VISIBLE);
brightness_center_text.setVisibility(View.VISIBLE);
brightnessBar.setProgress((int) brightPerc);
if (brightPerc < 30) {
brightnessIcon.setImageResource(R.drawable.ic_bright_min);
brightness_image.setImageResource(R.drawable.ic_bright_min);
} else if (brightPerc > 30 && brightPerc < 80) {
brightnessIcon.setImageResource(R.drawable.ic_bright_med);
brightness_image.setImageResource(R.drawable.ic_bright_med);
} else if (brightPerc > 80) {
brightnessIcon.setImageResource(R.drawable.ic_bright_max);
brightness_image.setImageResource(R.drawable.ic_bright_max);
}
brigtness_perc_center_text.setText(" " + (int) brightPerc);
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, (new_brightness));
WindowManager.LayoutParams layoutpars = window.getAttributes();
layoutpars.screenBrightness = brightness / (float) 255;
window.setAttributes(layoutpars);
}else if (intRight) {
vol_center_text.setVisibility(View.VISIBLE);
mediavolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int maxVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
double cal = (double) diffY * ((double)maxVol/(double)(device_height*4));
int newMediaVolume = mediavolume - (int) cal;
if (newMediaVolume > maxVol) {
newMediaVolume = maxVol;
} else if (newMediaVolume < 1) {
newMediaVolume = 0;
}
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, newMediaVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
double volPerc = Math.ceil((((double) newMediaVolume / (double) maxVol) * (double) 100));
vol_perc_center_text.setText(" " + (int) volPerc);
if (volPerc < 1) {
volIcon.setImageResource(R.drawable.ic_volume_mute);
vol_image.setImageResource(R.drawable.ic_volume_mute);
vol_perc_center_text.setVisibility(View.GONE);
} else if (volPerc >= 1) {
volIcon.setImageResource(R.drawable.ic_volume);
vol_image.setImageResource(R.drawable.ic_volume);
vol_perc_center_text.setVisibility(View.VISIBLE);
}
volumeBarContainer.setVisibility(View.VISIBLE);
volumeBar.setProgress((int) volPerc);
}
}else if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > (MIN_DISTANCE + 100)) {
tested_ok = true;
root.setVisibility(View.VISIBLE);
seekBar_center_text.setVisibility(View.VISIBLE);
onlySeekbar.setVisibility(View.VISIBLE);
(exoPlayer.getCurrentPosition() + (calculatedTime)));
}
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
screen_swipe_move=false;
tested_ok = false;
seekBar_center_text.setVisibility(View.GONE);
brightness_center_text.setVisibility(View.GONE);
vol_center_text.setVisibility(View.GONE);
brightnessBarContainer.setVisibility(View.GONE);
volumeBarContainer.setVisibility(View.GONE);
onlySeekbar.setVisibility(View.VISIBLE);
root.setVisibility(View.VISIBLE);
calculatedTime = (int) (exoPlayer.getCurrentPosition() + (calculatedTime));
exoPlayer.seekTo(calculatedTime);
break;
}
return super.onTouchEvent(event);
}
}
最佳答案
通过触摸控制亮度和音量我设法找到https://github.com/moneytoo/Player这让我可以使用更多功能来完成该功能并使用 exoplayer
图书馆
并且与 exoplayer 一样易于构建。
关于java - 无法控制 exoplayer 的音量和亮度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62045453/
大家好,我完成了这个基本的 C 程序,它向输入任何给定数字集的用户显示有序集、最小值、最大值、平均值和中值。我遇到的问题是,当我打印数字时,我必须使用诸如“3.2%f”之类的东西来设置标准的精度,我怎
我有这个基于 Python 的服务守护进程,它正在执行大量多路复用 IO(选择)。 从另一个脚本(也是 Python)我想查询这个服务守护进程的状态/信息和/或控制处理(例如暂停它、关闭它、更改一些参
我读到 Fortran 对表达式求值的顺序有严格的规则。对于某些数值算法来说,这一点非常重要。 数值 C 程序如何控制浮点运算的顺序并防止编译器“优化”到不需要的运算顺序,例如将 (a*b)*c 更改
上下文: 整个问题可以概括为我正在尝试复制调用system(或fork)的行为,但在 mpi 环境中。 (事实证明,你不能并行调用system。)这意味着我有一个程序在许多节点上运行,每个节点上有一个
我考虑过控制scanf来接受c中的任何输入。我的概念是等待10秒(或任何其他时间)来接受任何输入。10秒后它将退出并且不再接收任何输入。 int main(){ int a,b,c,d; sca
我正在尝试使用生成器停止 setTimeOut 上的执行流程。我究竟做错了什么?我无法让 console.log 每 1500 毫秒退出一次。我是 node 的新手,如果我在做一件非常愚蠢的事情,请不
我希望我的应用程序的 Activity 堆栈包含同一 Activity 的多个实例,每个实例处理不同的数据。因此,我将让 Activity A 在我的 Activity 堆栈中处理数据 a、b、c 和
我有这个 bash 文件,它向设备询问 OpenSSH 的 IP、密码等。 现在,如果我使用 ssh root@ip,我必须输入密码。这真的很烦人。第二;我不能让我的脚本向它发送命令。 这就是我想要的
我正在尝试测试我有权访问的机器的缓存属性。为此,我正在尝试读取内存并对其计时。我改变工作集大小和步幅访问模式以获得不同的测量值。 代码如下所示: clock1 = get_ticks() for (i
我正在尝试编写一个 makefile 来替换用于构建相当大的应用程序的脚本之一。 当前脚本一次编译一个文件,使用 make 的主要原因是并行化构建过程。使用 make -j 16 我目前在办公室服务器
我正在制作一个小的测试程序,它演示了一个粗糙的控制台界面。 该程序是一个低于标准的典型获取行、响应程序,它甚至不识别“退出”,并希望您通过按 control-c 强制退出。在 Mingw32 上完成。
好的,我有一个 VOIP 电话。我知道电话的 IP 地址和端口,并且可以完全访问电话,我正在使用它通过 SIP 中继调用 SIP 电话。 我基本上想随时查看手机上发生的事情,但我不知道从哪里开始。 如
是否可以指定 CWinApp::WriteProfileString() 使用的应用程序名称? 如果我使用 CWinApp::SetRegistryKey 将我的公司名称设置为“MyCompany”,
我正在尝试用 Python 控制 Tor。我在 stackoverflow 上阅读了其他几个关于这个主题的问题,但没有一个能回答这个问题。 我正在寻找一种方法,以便在命令运行时为您提供“新身份”、新
最近在做一个项目,涉及到iPhone设备和手表传输数据、控制彼此界面跳转,在网上找了很多资料,发现国内的网站这方面介绍的不多,而国外的网站写的也不是很全,所以在这写这篇文章,给大家参考一下,望大神指
我想增加图中值的范围。在示例中,值的范围从 50 到 200。但是,我需要按如下方式分配值:50 75 100 125 150 175 200 并且最好使用 scale_fill_gradientn
我有一个IconButton,当按下时波纹效果是圆形的并且比按钮的面积大,我怎样才能减少点击按钮时波纹效果的大小? IconButton( constraints
我正在使用代码契约(Contract)为我的项目生成附属程序集。基本上它为项目的 MyAssembly.dll 创建一个 MyAssembly.Contracts.dll。这应该放在你的程序集旁边,但
我想使用分面绘制图形,其中面板之间的边缘不同。面板按字母顺序自动排序(按照 ggplot 中的惯例)。一个简单的例子: library(igraph) library(ggraph) g <- mak
我想为我的 Android 应用程序创建一个小部件,以显示有关位置的一些实时详细信息,例如天气。但我想在任何时候允许最多 3 个小部件实例,每个实例都有不同的位置。我不确定该怎么做,也找不到任何信息。
我是一名优秀的程序员,十分优秀!