Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
e769d986
Commit
e769d986
authored
May 11, 2022
by
范玉宾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Solve the abnormal state of mediaplayer
parent
cac5df85
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
36 deletions
+32
-36
PlayMeditationActivity.kt
m-muse/src/main/java/com/yidianling/muse/activity/PlayMeditationActivity.kt
+22
-21
MediaPlayerManager.java
m-muse/src/main/java/com/yidianling/muse/helper/MediaPlayerManager.java
+10
-15
No files found.
m-muse/src/main/java/com/yidianling/muse/activity/PlayMeditationActivity.kt
View file @
e769d986
...
...
@@ -6,10 +6,8 @@ import android.os.Bundle
import
android.widget.SeekBar
import
com.alibaba.android.arouter.facade.annotation.Route
import
com.bumptech.glide.Glide
import
com.ydl.media.view.PlayerFloatHelper
import
com.ydl.ydlcommon.base.BaseActivity
import
com.ydl.ydlcommon.bean.StatusBarOptions
import
com.ydl.ydlcommon.utils.LogUtil
import
com.ydl.ydlcommon.utils.StatusBarUtils.Companion.setTransparentForImageView
import
com.ydl.ydlcommon.utils.StatusBarUtils.Companion.statusBarLightMode
import
com.ydl.ydlcommon.utils.remind.ToastHelper
...
...
@@ -32,6 +30,9 @@ class PlayMeditationActivity : BaseActivity() {
private
val
path
=
"http://file.kuyinyun.com/group1/M00/90/B7/rBBGdFPXJNeAM-nhABeMElAM6bY151.mp3"
private
val
newPath
=
"http://file.diyring.cc/UserRingWorksFile/0/50284096.mp3"
private
var
collected
=
false
private
var
isPlaying
=
false
...
...
@@ -66,21 +67,6 @@ class PlayMeditationActivity : BaseActivity() {
}
private
fun
initView
()
{
mMediaPlayer
=
MediaPlayerManager
.
getInstance
(
this
).
mediaPlayer
MediaPlayerManager
.
getInstance
(
this
).
path
=
path
val
currentPosition
=
mMediaPlayer
?.
currentPosition
duration
=
mMediaPlayer
?.
duration
?:
0
if
(
currentPosition
!=
null
){
exo_position
.
text
=
MediaPlayerTimeUtil
.
calculateTime
(
currentPosition
/
1000
)
}
if
(
duration
!=
null
){
exo_duration
.
text
=
MediaPlayerTimeUtil
.
calculateTime
(
duration
/
1000
)
}
Glide
.
with
(
this
)
.
load
(
bgUrl
)
.
into
(
iv_bg
)
...
...
@@ -135,6 +121,8 @@ class PlayMeditationActivity : BaseActivity() {
startActivity
(
Intent
(
this
,
MeditationTimeOffActivity
::
class
.
java
))
}
initMediaPlayer
()
exo_play
.
setOnClickListener
{
if
(
isPlaying
)
{
MediaPlayerManager
.
getInstance
(
this
).
pause
()
...
...
@@ -169,7 +157,7 @@ class PlayMeditationActivity : BaseActivity() {
}
exo_prev
.
setOnClickListener
{
MediaPlayerManager
.
getInstance
(
this
).
setNewPath
(
p
ath
)
MediaPlayerManager
.
getInstance
(
this
).
setNewPath
(
newP
ath
)
isPlaying
=
if
(
mMediaPlayer
?.
isPlaying
==
true
)
{
exo_play
.
setImageResource
(
R
.
drawable
.
icon_pause_play
)
if
(
duration
!=
null
)
{
...
...
@@ -188,7 +176,7 @@ class PlayMeditationActivity : BaseActivity() {
}
exo_next
.
setOnClickListener
{
MediaPlayerManager
.
getInstance
(
this
).
setNewPath
(
p
ath
)
MediaPlayerManager
.
getInstance
(
this
).
setNewPath
(
newP
ath
)
isPlaying
=
if
(
mMediaPlayer
?.
isPlaying
==
true
)
{
exo_play
.
setImageResource
(
R
.
drawable
.
icon_pause_play
)
if
(
duration
!=
null
)
{
...
...
@@ -268,12 +256,24 @@ class PlayMeditationActivity : BaseActivity() {
}
private
fun
initMediaPlayer
(){
mMediaPlayer
=
MediaPlayerManager
.
getInstance
(
this
).
mediaPlayer
MediaPlayerManager
.
getInstance
(
this
).
path
=
path
val
currentPosition
=
mMediaPlayer
?.
currentPosition
duration
=
mMediaPlayer
?.
duration
?:
0
if
(
currentPosition
!=
null
){
exo_position
.
text
=
MediaPlayerTimeUtil
.
calculateTime
(
currentPosition
/
1000
)
}
if
(
duration
!=
null
){
exo_duration
.
text
=
MediaPlayerTimeUtil
.
calculateTime
(
duration
/
1000
)
}
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
mTimer
.
cancel
()
mMediaPlayer
?
.
stop
()
mMediaPlayer
?
.
release
()
MediaPlayerManager
.
getInstance
(
this
)
.
stop
()
MediaPlayerManager
.
getInstance
(
this
)
.
release
()
}
}
\ No newline at end of file
m-muse/src/main/java/com/yidianling/muse/helper/MediaPlayerManager.java
View file @
e769d986
...
...
@@ -12,7 +12,6 @@ public class MediaPlayerManager {
private
MediaPlayer
mMediaPlayer
;
private
String
mPath
;
private
OnMediaPlayerManagerListener
mListener
;
private
volatile
static
MediaPlayerManager
instance
;
...
...
@@ -39,16 +38,16 @@ public class MediaPlayerManager {
public
void
setPath
(
String
path
)
{
mPath
=
path
;
if
(
mMediaPlayer
.
isPlaying
()){
mMediaPlayer
.
reset
();
}
try
{
if
(
mMediaPlayer
.
isPlaying
()){
mMediaPlayer
.
reset
();
}
mMediaPlayer
.
setDataSource
(
path
);
mMediaPlayer
.
prepare
();
}
catch
(
IO
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
// mMediaPlayer.start();
}
public
void
setNewPath
(
String
path
){
...
...
@@ -80,20 +79,16 @@ public class MediaPlayerManager {
mMediaPlayer
.
seekTo
(
position
);
}
public
void
setOnPreparedListener
(
OnMediaPlayerManagerListener
listener
){
mListener
=
listener
;
}
public
interface
OnMediaPlayerManagerListener
{
default
void
onPrepared
(
MediaPlayer
mediaPlayer
){};
default
void
onProgress
(
MediaPlayer
mediaPlayer
){};
}
public
void
stop
(){
if
(
mMediaPlayer
.
isPlaying
()){
mMediaPlayer
.
reset
();
}
}
public
void
release
(){
if
(
mMediaPlayer
!=
null
)
{
mMediaPlayer
.
reset
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment