- /**
- * 频谱的实现
- */
- private static final String TAG = "AudioFxActivity_1";
- private static final float VISUALIZER_HEIGHT_DIP = 160f;
- public static Visualizer mVisualizer;
- private LinearLayout mLinearLayout;
- private VisualizerView mVisualizerView;
- private MediaPlayer mp;// MediaPlayer对象
- private boolean isNext;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.playingmusic);
- Intent intent = this.getIntent();// 获取列表的Intent对象
- Bundle bundle = intent.getExtras();// Bundle存取数据,那么在播放界面提取数据喽
- _ids = bundle.getIntArray("_ids");// 歌名数组的ID,用来临时保存音乐的ID
- position = bundle.getInt("position");// 音乐播放位置
- _titles = bundle.getStringArray("_titles");// 音乐播放标题
- _artists = bundle.getStringArray("_artists");// 传过来的艺术家,歌名一个都不允许遗漏,否则空指针是必须的
- name = (TextView) findViewById(R.id.musicname);// 歌名
- // artist = (TextView) findViewById(R.id.singer);// 歌手,即艺术家
- lrcText = (TextView) findViewById(R.id.musiclrc);
- // playtime = (TextView) findViewById(R.id.playtime);// 左边正在播放时间
- // durationTime = (TextView) findViewById(R.id.duration);// 总时间,要转换的
- // albumpic = (ImageView) findViewById(R.id.albumPic);//专辑
- gesLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
- gesLib.load();
- gestureoverlay1 = (GestureOverlayView) this.findViewById(R.id.gestures1);
- MyOnGesturePerformedListener gpl = new MyOnGesturePerformedListener();
- gestureoverlay1.addOnGesturePerformedListener(gpl);
- // 频谱功能初始化
- mLinearLayout = (LinearLayout) findViewById(R.id.layout_audiofx);
- //Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, ""+_ids[position]);
- //mp = MediaPlayer.create(this, R.raw.ki);
- }
- private void setupVisualizerFxAndUI(int audioID)
- {
- mVisualizerView = new VisualizerView(this);
- mVisualizerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, (int) (VISUALIZER_HEIGHT_DIP * getResources().getDisplayMetrics().density)));
- mLinearLayout.addView(mVisualizerView);
- final int maxCR = Visualizer.getMaxCaptureRate();
- mVisualizer = new Visualizer(audioID);
- mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
- mVisualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener()
- {
- public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate)
- {
- mVisualizerView.updateVisualizer(bytes);
- }
- public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate)
- {
- mVisualizerView.updateVisualizer(fft);
- }
- }, maxCR / 2, false, true);
- mVisualizer.setEnabled(true);
- }
01-09 15:17:38.911: E/AndroidRuntime(933): Caused by: java.lang.IllegalStateException: setCaptureSize() called in wrong state: 2
01-09 15:17:38.911: E/AndroidRuntime(933): at android.media.audiofx.Visualizer.setCaptureSize(Visualizer.java:279)
一直出现这个错误,不知道是在这个activity的哪个地方添加mvisualizer.setEnabled(false)
求大神指点!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。