如何关闭默认媒体播放器?
我已经使用以下代码启动了默认媒体播放器:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(Environment.getExternalStorageDirectory()+("/background.mp3"));
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
但是,当文件完全播放后,我想退出媒体播放器。 我们如何关闭由“意图”启动的默认媒体播放器? 我尝试过使用“startActivityForResult()
”...但我不知道在哪里设置“result
”
I have started the default media player using the following code:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(Environment.getExternalStorageDirectory()+("/background.mp3"));
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
But, when the file is played completely, I want to exit the media player.
How do we close the default media player which is started by 'intent'?
I have tried using the "startActivityForResult()
"... But i don't know where to set the "result
"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在此示例中,我使用了 Mediaplayer,并且从原始文件夹 (res/raw.music.mp3) 中获取了资源。
我使用
stop();
媒体播放器的方法来停止它更多信息请点击此处
In this example i have use Mediaplayer and i have get my resource from raw folder (res/raw.music.mp3).
i have use
stop();
method of media player to stop itFor more here
你应该在统计你的活动后使用 finish()...
编辑
use mp.release();
私有静态最终字符串TAG =“VideoPlayer”;
you should have to use finish() after statring ur activity...
edit
use mp.release();
private static final String TAG = "VideoPlayer";
谢谢大家的回复,我遇到问题了...
使用了:
我在我的代码中 。
Environment.getExternalStorageDirectory()
就是问题所在!当我将其替换为“
/sdcard/background.mp3
”时,它可以正常工作......Thanks all for your reply, I got the problem...
I had used:
in my code. The
Environment.getExternalStorageDirectory()
was the problem!!!When i replaced it with "
/sdcard/background.mp3
" it works properly...