Android Open Source - android-qq Media






From Project

Back to project page android-qq.

License

The source code is released under:

Apache License

If you think the Android project android-qq listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.myandroid.util;
//from www . j  a va  2s  .c  o m
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Environment;
public class Media {
  // ?????????
  private MediaPlayer myPlayer;
  // ??
  private MediaRecorder myRecorder;
  // ????????????
  public String sendpath,receivepath;// path/xx.amr??????????
  public String name;//??????
  private File saveFilePath;
  public Media()
  {
    if (Environment.getExternalStorageState().equals(
        Environment.MEDIA_MOUNTED)) {
      try {
        sendpath = Environment.getExternalStorageDirectory()
            .getCanonicalPath().toString()
            + "/MessageMediaSend";
        File files = new File(sendpath);
        if (!files.exists()) {
          files.mkdir();
        }
        
        
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    if (Environment.getExternalStorageState().equals(
        Environment.MEDIA_MOUNTED)) {
      try {
        receivepath = Environment.getExternalStorageDirectory()
            .getCanonicalPath().toString()
            + "/MessageMediaReceive";
        File files = new File(receivepath);
        if (!files.exists()) {
          files.mkdir();
        }
        
        
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  //?????
  public void startRecord()
  {
    myRecorder = new MediaRecorder();
    // ?????????????
    myRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    // ??????????
    myRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
    // ????????
    myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    //??????
    this.name="AND"+Tools.getRandomId()
        + new SimpleDateFormat(
            "yyyyMMddHHmmss").format(System
            .currentTimeMillis())
        + ".amr";
    String paths = sendpath+"/"+name;
    saveFilePath = new File(paths);
    myRecorder.setOutputFile(saveFilePath
        .getAbsolutePath());
    try {
      saveFilePath.createNewFile();
      myRecorder.prepare();
    } catch (IOException e) {
      e.printStackTrace();
    }
    // ?????
    myRecorder.start();
  }
  //?????????
  public void stopRecord()
  {
    if (saveFilePath.exists() && saveFilePath != null) {
      myRecorder.stop();
      myRecorder.release();  
    }
  }
  //???
  public void destroy()
  {
    // ??????
    if (myPlayer.isPlaying()) {
      myPlayer.stop();
      myPlayer.release();
    }
    myPlayer.release();
    myRecorder.release();
  }
  //???????
  public void startPlay(String path0)
  {
    myPlayer = new MediaPlayer();
    try {
      myPlayer.reset();
      myPlayer.setDataSource(path0);
      if (!myPlayer.isPlaying()) {

        myPlayer.prepare();
        myPlayer.start();
      } else {
        myPlayer.pause();
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  //??????
  public void stopPlay()
  {
    if (myPlayer.isPlaying()) {
      myPlayer.stop();
    }
  }
  
}




Java Source Code List

com.myandroid.activity.ChatActivity.java
com.myandroid.activity.FileAcitivity.java
com.myandroid.activity.MainActivity.java
com.myandroid.activity.MediaDialog.java
com.myandroid.activity.SettingDialog.java
com.myandroid.util.Audio.java
com.myandroid.util.FileTcpClient.java
com.myandroid.util.FileTcpServer.java
com.myandroid.util.MediaTcpClient.java
com.myandroid.util.MediaTcpServer.java
com.myandroid.util.Media.java
com.myandroid.util.Msg.java
com.myandroid.util.Tools.java
com.myandroid.util.User.java