Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart7.png 55% of files have more coverage
17   90   11   2,43
4   48   0,65   7
7     1,57  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  VisualizerController       Line # 32 17 11 64,3% 0.64285713
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2011 (C) Sindre Mehus
18    */
19    package net.sourceforge.subsonic.androidapp.audiofx;
20   
21    import android.content.Context;
22    import android.media.MediaPlayer;
23    import android.media.audiofx.Visualizer;
24    import android.util.Log;
25   
26    /**
27    * Backward-compatible wrapper for {@link Visualizer}, which is API Level 9.
28    *
29    * @author Sindre Mehus
30    * @version $Id$
31    */
 
32    public class VisualizerController {
33   
34    private static final String TAG = VisualizerController.class.getSimpleName();
35    private static final int PREFERRED_CAPTURE_SIZE = 128; // Must be a power of two.
36   
37    private final Context context;
38    private Visualizer visualizer;
39   
40    // Class initialization fails when this throws an exception.
 
41  1 toggle static {
42  1 try {
43  1 Class.forName("android.media.audiofx.Visualizer");
44    } catch (Exception ex) {
45  0 throw new RuntimeException(ex);
46    }
47    }
48   
49    /**
50    * Throws an exception if the {@link Visualizer} class is not available.
51    */
 
52  1 toggle public static void checkAvailable() throws Throwable {
53    // Calling here forces class initialization.
54    }
55   
 
56  1 toggle public VisualizerController(Context context, MediaPlayer mediaPlayer) {
57  1 this.context = context;
58  1 try {
59  1 visualizer = new Visualizer(mediaPlayer.getAudioSessionId());
60    } catch (Throwable x) {
61  0 Log.w(TAG, "Failed to create visualizer.", x);
62    }
63   
64  1 if (visualizer != null) {
65  1 int[] captureSizeRange = Visualizer.getCaptureSizeRange();
66  1 int captureSize = Math.max(PREFERRED_CAPTURE_SIZE, captureSizeRange[0]);
67  1 captureSize = Math.min(captureSize, captureSizeRange[1]);
68  1 visualizer.setCaptureSize(captureSize);
69    }
70    }
71   
 
72  1 toggle public boolean isAvailable() {
73  1 return visualizer != null;
74    }
75   
 
76  0 toggle public boolean isEnabled() {
77  0 return isAvailable() && visualizer.getEnabled();
78    }
79   
 
80  0 toggle public void release() {
81  0 if (isAvailable()) {
82  0 visualizer.release();
83    }
84    }
85   
 
86  28 toggle public Visualizer getVisualizer() {
87  28 return visualizer;
88    }
89    }
90