blob: b5e16cf9b296895cd15547a8b10c602b04bfdee5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/**
* Copyright 2011, Felix Palmer
*
* Licensed under the MIT license:
* http://creativecommons.org/licenses/MIT/
*/
package com.pheelicks.app;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import com.pheelicks.visualizer.R;
import com.pheelicks.visualizer.VisualizerView;
/**
* Basic demo to show how to use VisualizerView
*
*/
public class MainActivity extends Activity {
private MediaPlayer mPlayer;
private VisualizerView mVisualizerView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init()
{
mPlayer = MediaPlayer.create(this, R.raw.test);
mPlayer.setLooping(true);
mPlayer.start();
mVisualizerView = (VisualizerView) findViewById(R.id.visualizerView);
mVisualizerView.link(mPlayer);
}
// Cleanup
private void cleanUp()
{
if (mPlayer != null)
{
mVisualizerView.release();
mPlayer.release();
mPlayer = null;
}
}
@Override
protected void onResume()
{
super.onResume();
if(mPlayer == null)
{
init();
}
else
{
mPlayer.start();
}
}
@Override
protected void onPause()
{
if (isFinishing())
{
cleanUp();
}
else
{
mPlayer.pause();
}
super.onPause();
}
@Override
protected void onDestroy()
{
cleanUp();
super.onDestroy();
}
// Actions for buttons defined in xml
public void startPressed(View view)
{
mPlayer.start();
}
public void stopPressed(View view)
{
mPlayer.stop();
}
}
|