日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java调节音量代码_用Java调用VC音量控制程序_java

發(fā)布時間:2025/4/16 java 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java调节音量代码_用Java调用VC音量控制程序_java 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

前言

本文通過java的Runtime接口來實現(xiàn)調(diào)用其他語言實現(xiàn)的應用程序,進而來實現(xiàn)對計算機硬件信息的監(jiān)控和控制.本文是多媒體信息系統(tǒng)的一個部分,就是調(diào)整計算機音量。

使用VC編寫音量控制程序

本控制示例使用VC6.0編寫,主要是調(diào)用系統(tǒng)的API來實現(xiàn),

mixerGetLineInfo 獲取Master Volume Control.

http://www.gaodaima.com/64887.html用Java調(diào)用VC音量控制程序_java

mixerGetControlDetails 獲取 Volume Control 信息

mixerSetControlDetails 設置 Volume Control 信息

最終編譯成Console類型的Dos執(zhí)行的程序VolumeControl.exe。這個程序?qū)崿F(xiàn)三個功能:

1.獲取音量 VolumeControl.exe 0

2.增加音量 VolumeControl.exe 1

3.減少音量 VolumeControl.exe 2

下面我們用Java設計創(chuàng)建一個Panel用于顯示音量并調(diào)用應用程序?qū)崿F(xiàn)對音量的實際控制,本例中使用自定義Progress顯示VolumeTracker.java

實現(xiàn)原理如下:

使用一個線程動態(tài)刷新頁面,主線程用來實現(xiàn)對音量的控制.其實現(xiàn)代碼如下:

import java.awt.*;

import java.awt.font.*;

import java.awt.geom.*;

import java.awt.event.*;

import java.text.AttributedString;

import java.text.AttributedCharacterIterator;

import javax.swing.*;

import javax.swing.border.*;

import javax.swing.table.*;

import javax.swing.event.*;

import java.io.*;

public class VolumeTracker extends JPanel implements Runnable

{

String welcomeStr = "Welcome to Java Sound";

Thread pbThread;

Color background = Color.white;

//new Color(20, 20, 20);

Color jfcBlue = Color.blue;

//new Color(204, 204, 255);

Color jfcDarkBlue = jfcBlue.darker();

Font font24 = new Font("serif", Font.BOLD, 24);

Font font28 = new Font("serif", Font.BOLD, 28);

Font font42 = new Font("serif", Font.BOLD, 42);

FontMetrics fm28, fm42;

String errStr=null;

String currentName=null;

double duration = 100.0;

double seconds = 82.0;

boolean midiEOM, audioEOM;

public VolumeTracker()

{

fm28 = getFontMetrics(font28);

fm42 = getFontMetrics(font42);

initVolume();

start();

}

private void initVolume()

{

try

{

//這一段小程序?qū)崿F(xiàn)對VC創(chuàng)建程序的調(diào)用

Runtime rt = Runtime.getRuntime(); //Time and Date.

//mngPathTool類,提供了一個獲取當前路徑的方法

mngPathTool tool = new mngPathTool();

String sexec = tool.getCurPath()+ "//binex//VolumeControl.exe 0";

Process child = rt.exec(sexec);

//獲取控制臺輸出的內(nèi)容,進而獲得音量的大小

InputStreamReader reader = new InputStreamReader(child.getInputStream());

char[] chr = new char[5];

reader.read(chr) ;

String s="";

for(int i=0;i<5;i++)

{

if(chr[i]>='0' && chr[i]<='9') s+=chr[i];

}

//System.out.println(s);

Integer nVolume = new Integer(s);

seconds = nVolume.intValue();

child.waitFor();

//這一段小程序?qū)崿F(xiàn)對VC創(chuàng)建程序的調(diào)用

}

catch(Exception e1)

{

e1.printStackTrace();

}

}

public void paint(Graphics g)

{

//畫圖來實現(xiàn)百分比Tracker

Graphics2D g2 = (Graphics2D) g;

Dimension d = getSize();

g2.setBackground(background);

g2.clearRect(0, 0, d.width, d.height);

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

g2.setColor(jfcBlue);

double tseconds = duration-seconds;

if (tseconds > 0.0)

{

int num = 20;

int progress = (int) (tseconds / duration * num);

double hh = ((double) (d.height - 4) / (double) num);

double ww = (int)(d.width-4);

double x = 0.0;

for ( ; x < progress; x+=1.0)

{

g2.fill(new Rectangle2D.Double(d.width-ww-2, x*hh+2, ww, hh));

g2.fill3DRect((int)(d.width-ww-2),(int) (x*hh+2),(int) ww, (int)hh,true);

}

g2.setColor(jfcDarkBlue);

for ( ; x < num; x+=1.0)

{

g2.fill(new Rectangle2D.Double(d.width-ww-2, x*hh+2, ww, hh));

g2.fill3DRect((int)(d.width-ww-2),(int) (x*hh+2),(int) ww, (int)hh,true);

}

}

}

public void start()

{

pbThread = new Thread(this);

pbThread.setName("PlaybackMonitor");

pbThread.start();

}

public void stop()

{

if (pbThread != null)

{

pbThread.interrupt();

}

pbThread = null;

}

public void run()

{

while (pbThread != null)

{

try

{

pbThread.sleep(99);

}

catch (Exception e)

{

break;

}

repaint();

}

pbThread = null;

}

public void addVolume()

{

changeVolume(false);

initVolume();

}

public void minusVolume()

{

changeVolume(true);

initVolume();

}

//control sound volume.

private void changeVolume(boolean bIsMinus)

{

try

{

Runtime rt = Runtime.getRuntime();

//Sound Control mngPathTool

tool = new mngPathTool();

String sexec;

if(bIsMinus)

sexec= tool.getCurPath()+ "//binex//VolumeControl.exe 2";

else

sexec= tool.getCurPath()+ "//binex//VolumeControl.exe 1";

rt.exec(sexec);

}catch(Exception e1){e1.printStackTrace(); }

}

}

// End VolumeTracker

創(chuàng)建一個JFrame用于顯示 VolumeControl.java

設置頁面背景,創(chuàng)建顯示上述Panel的容器.

創(chuàng)建對話框用于彈出顯示音量控制界面 JVolumeDlg.java

創(chuàng)建一個對話框來顯示上個步驟生成的Frame,并提供事件控制容器.

事件流向---> JVolumeDlg -- VolumeControl --- VolumeTracker

總結(jié)

Java Runtime 接口提供了調(diào)用其他應用程序的接口,通過這個接口,可以實現(xiàn)對計算機硬件的控制和監(jiān)控. 同時通過界面線程可以實現(xiàn)相對復雜的應用程序界面的開發(fā)。

歡迎大家閱讀《用Java調(diào)用VC音量控制程序_java》,跪求各位點評,若覺得好的話請收藏本文,by 搞代碼

微信 賞一包辣條吧~

支付寶 賞一聽可樂吧~

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的java调节音量代码_用Java调用VC音量控制程序_java的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。