Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.hardware.Camera;
      4 import android.media.MediaRecorder;
      5 import android.view.Surface;
      6 import com.xtremelabs.robolectric.internal.Implementation;
      7 import com.xtremelabs.robolectric.internal.Implements;
      8 
      9 /**
     10  * Shadows the {@code MediaRecorder} class.
     11  */
     12 @Implements(MediaRecorder.class)
     13 public class ShadowMediaRecorder {
     14 
     15     // Recording machine state, as per:
     16     // http://developer.android.com/reference/android/media/MediaRecorder.html
     17     public static final int STATE_ERROR = -1;
     18     public static final int STATE_INITIAL = 1;
     19     public static final int STATE_INITIALIZED = 2;
     20     public static final int STATE_DATA_SOURCE_CONFIGURED = 3;
     21     public static final int STATE_PREPARED = 4;
     22     public static final int STATE_RECORDING = 5;
     23     public static final int STATE_RELEASED = 6;
     24 
     25     private int state;
     26 
     27     private Camera camera;
     28     private int audioChannels;
     29     private int audioEncoder;
     30     private int audioBitRate;
     31     private int audioSamplingRate;
     32     private int audioSource;
     33     private int maxDuration;
     34     private long maxFileSize;
     35     private String outputPath;
     36     private int outputFormat;
     37     private int videoEncoder;
     38     private int videoBitRate;
     39     private int videoFrameRate;
     40     private int videoWidth;
     41     private int videoHeight;
     42     private int videoSource;
     43 
     44     private Surface previewDisplay;
     45     private MediaRecorder.OnErrorListener errorListener;
     46     private MediaRecorder.OnInfoListener infoListener;
     47 
     48     public void __constructor__() {
     49         state = STATE_INITIAL;
     50     }
     51 
     52     @Implementation
     53     public void setAudioChannels(int numChannels) {
     54         audioChannels = numChannels;
     55     }
     56 
     57     @Implementation
     58     public void setAudioEncoder(int audio_encoder) {
     59         audioEncoder = audio_encoder;
     60         state = STATE_DATA_SOURCE_CONFIGURED;
     61     }
     62 
     63     @Implementation
     64     public void setAudioEncodingBitRate(int bitRate) {
     65         audioBitRate = bitRate;
     66     }
     67 
     68     @Implementation
     69     public void setAudioSamplingRate(int samplingRate) {
     70         audioSamplingRate = samplingRate;
     71     }
     72 
     73     @Implementation
     74     public void setAudioSource(int audio_source) {
     75         audioSource = audio_source;
     76         state = STATE_INITIALIZED;
     77     }
     78 
     79     @Implementation
     80     public void setCamera(Camera c) {
     81         camera = c;
     82     }
     83 
     84     @Implementation
     85     public void setMaxDuration(int max_duration_ms) {
     86         maxDuration = max_duration_ms;
     87     }
     88 
     89     @Implementation
     90     public void setMaxFileSize(long max_filesize_bytes) {
     91         maxFileSize = max_filesize_bytes;
     92     }
     93 
     94     @Implementation
     95     public void setOnErrorListener(MediaRecorder.OnErrorListener l) {
     96         errorListener = l;
     97     }
     98 
     99     @Implementation
    100     public void setOnInfoListener(MediaRecorder.OnInfoListener listener) {
    101         infoListener = listener;
    102     }
    103 
    104     @Implementation
    105     public void setOutputFile(String path) {
    106         outputPath = path;
    107         state = STATE_DATA_SOURCE_CONFIGURED;
    108     }
    109 
    110     @Implementation
    111     public void setOutputFormat(int output_format) {
    112         outputFormat = output_format;
    113         state = STATE_DATA_SOURCE_CONFIGURED;
    114     }
    115 
    116     @Implementation
    117     public void setPreviewDisplay(Surface sv) {
    118         previewDisplay = sv;
    119         state = STATE_DATA_SOURCE_CONFIGURED;
    120     }
    121 
    122     @Implementation
    123     public void setVideoEncoder(int video_encoder) {
    124         videoEncoder = video_encoder;
    125         state = STATE_DATA_SOURCE_CONFIGURED;
    126     }
    127 
    128     @Implementation
    129     public void setVideoEncodingBitRate(int bitRate) {
    130         videoBitRate = bitRate;
    131     }
    132 
    133     @Implementation
    134     public void setVideoFrameRate(int rate) {
    135         videoFrameRate = rate;
    136         state = STATE_DATA_SOURCE_CONFIGURED;
    137     }
    138 
    139     @Implementation
    140     public void setVideoSize(int width, int height) {
    141         videoWidth = width;
    142         videoHeight = height;
    143         state = STATE_DATA_SOURCE_CONFIGURED;
    144     }
    145 
    146     @Implementation
    147     public void setVideoSource(int video_source) {
    148         videoSource = video_source;
    149         state = STATE_INITIALIZED;
    150     }
    151 
    152     @Implementation
    153     public void prepare() {
    154         state = STATE_PREPARED;
    155     }
    156 
    157     @Implementation
    158     public void start() {
    159         state = STATE_RECORDING;
    160     }
    161 
    162     @Implementation
    163     public void stop() {
    164         state = STATE_INITIAL;
    165     }
    166 
    167     @Implementation
    168     public void reset() {
    169         state = STATE_INITIAL;
    170     }
    171 
    172     @Implementation
    173     public void release() {
    174         state = STATE_RELEASED;
    175     }
    176 
    177     public Camera getCamera() {
    178         return camera;
    179     }
    180 
    181     public int getAudioChannels() {
    182         return audioChannels;
    183     }
    184 
    185     public int getAudioEncoder() {
    186         return audioEncoder;
    187     }
    188 
    189     public int getAudioEncodingBitRate() {
    190         return audioBitRate;
    191     }
    192 
    193     public int getAudioSamplingRate() {
    194         return audioSamplingRate;
    195     }
    196 
    197     public int getAudioSource() {
    198         return audioSource;
    199     }
    200 
    201     public int getMaxDuration() {
    202         return maxDuration;
    203     }
    204 
    205     public long getMaxFileSize() {
    206         return maxFileSize;
    207     }
    208 
    209     public String getOutputPath() {
    210         return outputPath;
    211     }
    212 
    213     public int getOutputFormat() {
    214         return outputFormat;
    215     }
    216 
    217     public int getVideoEncoder() {
    218         return videoEncoder;
    219     }
    220 
    221     public int getVideoEncodingBitRate() {
    222         return videoBitRate;
    223     }
    224 
    225     public int getVideoFrameRate() {
    226         return videoFrameRate;
    227     }
    228 
    229     public int getVideoWidth() {
    230         return videoWidth;
    231     }
    232 
    233     public int getVideoHeight() {
    234         return videoHeight;
    235     }
    236 
    237     public int getVideoSource() {
    238         return videoSource;
    239     }
    240 
    241     public Surface getPreviewDisplay() {
    242         return previewDisplay;
    243     }
    244 
    245     public MediaRecorder.OnErrorListener getErrorListener() {
    246         return errorListener;
    247     }
    248 
    249     public MediaRecorder.OnInfoListener getInfoListener() {
    250         return infoListener;
    251     }
    252 
    253     public int getState() {
    254         return state;
    255     }
    256 }
    257