Android Open Source - MicDroid Recording






From Project

Back to project page MicDroid.

License

The source code is released under:

GNU General Public License

If you think the Android project MicDroid 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

/* Recording.java
//from  w  w w .  jav  a  2s .  co m
   Copyright (c) 2010 Ethan Chen

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package com.intervigil.micdroid.model;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import android.os.Parcel;
import android.os.Parcelable;

import com.intervigil.wave.WaveReader;
import com.intervigil.wave.exception.InvalidWaveException;

public class Recording implements Parcelable {
    public static final int WAVE_HEADER_SIZE = 44;
    public static final int MILLISECONDS_IN_SECOND = 1000;

    private String recordingPath;
    private String recordingName;
    private int recordingLength;
    private int recordingSize;

    public static final Parcelable.Creator<Recording> CREATOR = new Parcelable.Creator<Recording>() {
        public Recording createFromParcel(Parcel in) {
            return new Recording(in);
        }

        public Recording[] newArray(int size) {
            return new Recording[size];
        }
    };

    public Recording() {
    }

    public Recording(File file) throws FileNotFoundException, InvalidWaveException, IOException {
        WaveReader reader = new WaveReader(file);
        reader.openWave();
        this.recordingPath = file.getParent();
        this.recordingName = file.getName();
        this.recordingLength = reader.getLength();
        this.recordingSize = reader.getDataSize() + WAVE_HEADER_SIZE;
        reader.closeWaveFile();
        reader = null;
    }

    private Recording(Parcel in) {
        this.recordingPath = in.readString();
        this.recordingName = in.readString();
        this.recordingLength = in.readInt();
        this.recordingSize = in.readInt();
    }

    public Recording(String path, String name, int length, int size) {
        this.recordingPath = path;
        this.recordingName = name;
        this.recordingLength = length;
        this.recordingSize = size;
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel out, int flags) {
        out.writeString(recordingPath);
        out.writeString(recordingName);
        out.writeInt(recordingLength);
        out.writeInt(recordingSize);
    }

    public File asFile() {
        return new File(recordingPath + File.separator + recordingName);
    }

    public String getAbsolutePath() {
        return recordingPath + File.separator + recordingName;
    }

    public String getName() {
        // gets recording name, typically the file name
        return recordingName;
    }

    public int getLengthInMs() {
        return recordingLength * 1000;
    }

    public String getLength() {
        // gets recording length in MM:SS format
        int minutes = recordingLength / 60;
        int seconds = recordingLength % 60;
        return String.format("%d:%02d", minutes, seconds);
    }

    public int getSize() {
        return recordingSize;
    }

    public void setPath(String path) {
        // sets the recording path, where it is located
        recordingPath = path;
    }

    public void setName(String name) {
        // sets recording name, typically the file name
        recordingName = name;
    }

    public void setLength(int length) {
        // sets recording length, in number of seconds
        recordingLength = length;
    }

    public void setSize(int size) {
        recordingSize = size;
    }

    public boolean delete() {
        return new File(recordingPath + File.separator + recordingName).delete();
    }

    public void moveTo(File destination) {
        File recordingFile = new File(recordingPath + File.separator
                + recordingName);
        recordingPath = destination.getParent();
        recordingName = destination.getName();
        recordingFile.renameTo(destination);
    }
}




Java Source Code List

com.intervigil.micdroid.AutotalentTask.java
com.intervigil.micdroid.Constants.java
com.intervigil.micdroid.FileNameEntry.java
com.intervigil.micdroid.InstrumentalLibrary.java
com.intervigil.micdroid.MicApplication.java
com.intervigil.micdroid.Mic.java
com.intervigil.micdroid.Preferences.java
com.intervigil.micdroid.RecordingLibrary.java
com.intervigil.micdroid.RecordingPlayer.java
com.intervigil.micdroid.SeekableMediaPlayer.java
com.intervigil.micdroid.StartupDialog.java
com.intervigil.micdroid.Timer.java
com.intervigil.micdroid.helper.AdHelper.java
com.intervigil.micdroid.helper.ApplicationHelper.java
com.intervigil.micdroid.helper.AudioHelper.java
com.intervigil.micdroid.helper.DialogHelper.java
com.intervigil.micdroid.helper.HeadsetHelper.java
com.intervigil.micdroid.helper.MediaStoreHelper.java
com.intervigil.micdroid.helper.PreferenceHelper.java
com.intervigil.micdroid.helper.RecordingOptionsHelper.java
com.intervigil.micdroid.helper.UpdateHelper.java
com.intervigil.micdroid.interfaces.DependentTask.java
com.intervigil.micdroid.interfaces.Recorder.java
com.intervigil.micdroid.model.Recording.java
com.intervigil.micdroid.recorder.JNIRecorder.java
com.intervigil.micdroid.recorder.SimpleRecorder.java
com.intervigil.micdroid.recorder.SipdroidRecorder.java
org.openintents.intents.FileManagerIntents.java