重新创建活动时连续播放音乐?(Continuous playing of music when re

编程入门 行业动态 更新时间:2024-10-22 23:11:54
重新创建活动时连续播放音乐?(Continuous playing of music when re-creating an Activity?)

我目前有一个播放音乐的活动。 当活动被破坏(即用户旋转屏幕)时,我让应用程序存储音乐播放器的状态,然后在重新创建活动后从歌曲中的确切位置播放音乐。

我唯一的问题是,当重新创建活动时,音乐会有明显的停顿。 关于如何在更有效地重新创建应用程序方面提高活动性能的任何想法。 我知道我可以通过在android清单中使用configChanges标签来阻止活动不重新创建对象,但我想避免这种情况。

在单独的服务中运行音乐是我唯一的选择吗?

I currently have an activity that plays music. When the activity is destroyed (i.e. user rotates the screen) I have the application store the music player's state and then play the music from the exact spot in the song once the activity is re-created.

My only issue is that there is a noticeable pause in the music when the activity is re-created. Any ideas on how to increase the activity's performance in regards to re-creating the app more efficiently. I know I can stop the activity to not re-create objects by using the configChanges tag in the android manifest but I would like to avoid that.

Is running the music in a separate service my only option?

最满意答案

由于活动被破坏,无论你做什么,它都会暂停。 您应该为此目的使用服务。 服务在单独的线程上运行,不受您的活动影响。 有很多关于服务的教程和stackoverflow问题

Since the activity is destroyed it will pause no matter what you do. You should use a Service for this purpose. A service runs on a separate thread and is not effected by your activity. There's loads of tutorials and stackoverflow questions for services

更多推荐

本文发布于:2023-07-26 00:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建活动   连续播放   音乐   music   playing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!