Skip to content

Commit

Permalink
修复无法在程序内修改音量的问题 (#66)
Browse files Browse the repository at this point in the history
* 修复无法调整音量的问题

* fix

* fix

* fix

* update
  • Loading branch information
zkitefly authored Jun 5, 2024
1 parent 94636ee commit d8113d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<uses-feature
android:name="android.hardware.touchscreen"
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/eanyatonic/cctvViewer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -39,6 +40,8 @@

public class MainActivity extends AppCompatActivity {

private AudioManager audioManager;

private WebView webView; // 导入 WebView

private String[] liveUrls = {
Expand Down Expand Up @@ -173,6 +176,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// 获取 AudioManager 实例
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

// 初始化 WebView
webView = findViewById(R.id.webView);

Expand Down Expand Up @@ -470,7 +476,11 @@ private void getDivDisplayPropertyAndDoSimulateTouch() {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (menuOverlay.hasFocus()) {
if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
} else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
} else if (menuOverlay.hasFocus()) {
// menuOverlay具有焦点
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){
// 按下返回键
Expand Down

0 comments on commit d8113d8

Please sign in to comment.