我使用的Android媒体播放器类,用于播放通知声音在我的Android应用程序。
I am using android media player class for playing notification sound in my android Application.
MediaPlayer player = MediaPlayer.create(getApplicationContext(), R.raw.notify);
player.setLooping(false);
player.start();
我需要扮演不同的通知声音在不同的活动,所以每次我要玩,我需要创建的媒体播放器实例,然后我需要说的启动声音。
I need to play different notification sounds in different Activities, so every time i need to play the sound i need to create media player instance and then i need to say start.
不过。
有人可以请建议我实现它的更好的方法。 从我的角度来看,我将创建一个单独的类,我会添加所有在这个类的相关功能的MediaPlayer。
Can someone please suggest me the better way of implementing it. From my point of view i will create one singleton class and i will add all the MediaPlayer related function in this class.
感谢。
您应该考虑在 Singleton模式 。使类MyPlayer,有一个静态方法 getMediaPlayer()
返回的MediaPlayer的同一个实例每次调用的时候。
You should consider the Singleton pattern. Make a class MyPlayer that has a static method getMediaPlayer()
that returns the same instance of MediaPlayer each time called.
上一篇:而点击的ListView动态TextView的错误错误、动态、ListView、TextView
下一篇:与imageviews作为一个孩子HorizontalScrollView虽然滚动图像的中心位于屏幕应该扮演动画?作为一个、图像、屏幕、孩子