立即启动MediaPlayer并更新MediaPlayerControl

时间:2017-03-24 17:26:00

标签: android

我希望在首次启动活动时立即开始播放声音,并且我希望public class Guide extends AppCompatActivity implements MediaPlayerControl, MediaPlayer.OnPreparedListener { private MediaPlayer m_audio_player; private MediaController m_audio_controller; private Handler handler = new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); set_up_audio(); } private void set_up_audio(){ m_audio_player = MediaPlayer.create(this, *SOMESOUNDFILE*); m_audio_player.setOnPreparedListener(this); m_audio_controller = new MediaController(this); } public void onPrepared(MediaPlayer mediaPlayer) { m_audio_controller.setMediaPlayer(this); m_audio_controller.setAnchorView(findViewById(R.id.main_audio_view)); handler.post(new Runnable() { public void run() { m_audio_controller.setEnabled(true); m_audio_controller.show(); m_audio_player.start(); // how do I update m_audio_controller's state here? } }); } } 对象反映此更改。在下面给出的代码中,控件将以播放模式激活而不是暂停模式开始(因为文件已在播放)。

/usr/local/bin/php /usr/local/bin/wp --skip-plugins=cat /home2/mysite/public_html/skipplugins.txt cron event run --all --path=/home2/mysite/public_html

我该怎么做?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。如果我在首次启动播放器后调用show,它确实有效。

m_audio_player.start();
m_audio_controller.show();