| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 788 人关注过本帖
标题:请问在application下怎么重复播反声音
只看楼主 加入收藏
xjgycc
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-2-2
收藏
 问题点数:0 回复次数:8 
请问在application下怎么重复播反声音
同上
搜索更多相关主题的帖子: 声音 application 
2005-08-18 00:26
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
show code

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-08-18 02:12
xjgycc
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-2-2
收藏
得分:0 

import sun.audio.*;

import java.io.*;

class Sound

{

public Sound()

{

try {

FileInputStream fileau=new FileInputStream("back1.mid");

AudioStream as=new AudioStream(fileau);

AudioPlayer.player.start(as);

}

catch (Exception e) {}

}

} 这个好像没重复的

2005-08-18 15:14
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
xjgycc, 这个不是重复不重复的问题,首先得有播放声音的效果,根据这段代码就可以播放声音了?在我这边根本不行。 我最近在写一个程序,里面要用到录音,对录音文件做时间段测量,当然也要有放音功能。等做好了,我在这里贴一下,你可以下载以后去看看。估计还得两个星期才可以完成。 好了,你这个帖子暂时就回答到这里。

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-08-18 16:44
深夜狼
Rank: 1
来 自:广西桂林
等 级:新手上路
帖 子:348
专家分:0
注 册:2005-5-9
收藏
得分:0 
用循环不行么?
2005-08-18 18:43
xjgycc
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-2-2
收藏
得分:0 
这段代码我这是可以运行的,就是没循环的方法啊
2005-08-18 21:43
牛虻
Rank: 1
等 级:新手上路
威 望:1
帖 子:472
专家分:0
注 册:2004-10-1
收藏
得分:0 
建一个thread,run一下

土冒
2005-08-18 23:05
xjgycc
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-2-2
收藏
得分:0 
?????????????
2005-08-19 10:18
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
//try it
import javax.sound.sampled.AudioInputStream;
import
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.AudioSystem;
import
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;


public class Playback extends Thread //implements Runnable
{
  final int bufSize = 16384;
  SourceDataLine line;
  File file;
  String fileName = "untitled";
  AudioInputStream audioInputStream;
  long duration;
  
  public Playback(String strFilename)
  {
    file = new File(strFilename);
    setName("Playback");
  }
  
  private void shutDown(String message)
  {
    if (message != null)
    {
      System.err.println(message);
    }
  }

  public void run()
  {
    // reload the file if loaded by file
    if (file != null)
    {
      createAudioInputStream(file);
    }
   
    // make sure we have something to play
    if (audioInputStream == null)
    {
      shutDown("No loaded audio to play back");
      return;
    }
   
    // get an AudioInputStream of the desired format for playback
    AudioFormat format = audioInputStream.getFormat();
    AudioInputStream playbackInputStream = AudioSystem.getAudioInputStream(format, audioInputStream);

    if (playbackInputStream == null)
    {
      shutDown("Unable to convert stream of format " + audioInputStream + " to format " + format);
      return;
    }

    // define the required attributes for our line,
    // and make sure a compatible line is supported.
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
    if (!AudioSystem.isLineSupported(info))
    {
      shutDown("Line matching " + info + " not supported.");
      return;
    }

    // get and open the source data line for playback.
    try
    {
      line = (SourceDataLine) AudioSystem.getLine(info);
      line.open(format, bufSize);
    }
    catch (LineUnavailableException ex)
    {
      shutDown("Unable to open the line: " + ex);
      return;
    }

    // play back the captured audio data
    int frameSizeInBytes = format.getFrameSize();
    int bufferLengthInFrames = line.getBufferSize() / 8;
    int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
    byte[] data = new byte[bufferLengthInBytes];
    int numBytesRead = 0;

    // start the source data line
    line.start();
    while (this != null)
    {
      try
      {
        if ((numBytesRead = playbackInputStream.read(data)) == -1)
        {
          break;
        }
        int numBytesRemaining = numBytesRead;
        while (numBytesRemaining > 0 )
        {
          numBytesRemaining -= line.write(data, 0, numBytesRemaining);
        }
      }
      catch (Exception e)
      {
        shutDown("Error during playback: " + e);
        break;
      }
    }
   
    // we reached the end of the stream.  let the data play out, then
    // stop and close the line.
    if (this != null)
    {
      line.drain();
    }
    line.stop();
    line.close();
    line = null;
    shutDown(null);
  }
  public void createAudioInputStream(File file)
  {
    if (file != null && file.isFile())
    {
      try
      {
        audioInputStream = AudioSystem.getAudioInputStream(file);
        fileName = file.getName();
        duration =(long)((audioInputStream.getFrameLength() * 1000) /audioInputStream.getFormat().getFrameRate());
      }
      catch (Exception ex)
      {
       // reportStatus(ex.toString());
      }
    }
    else
    {
     // reportStatus("Audio file required.");
    }
  }
  public static void main(String [] args)
  {
    Playback pb = new Playback("untitled");  // here you should set your soundfilename
    pb.start();
    for(int i = 0; i<3; i++)      // for example you can repeat 3 times
    {
      while(pb.isAlive())
        ;
      if(pb == null)
      {
        pb = new Playback("untitled");
        pb.start();
      }
      else
        pb.run();
    }
  }
}

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-08-23 14:37
快速回复:请问在application下怎么重复播反声音
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029786 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved