Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Signal-Android
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
GitHub Mirror
Signal
Signal-Android
Commits
98fc3e5b
Commit
98fc3e5b
authored
3 years ago
by
Alex Hart
Browse files
Options
Downloads
Patches
Plain Diff
Log warning instead of throwing NPE for voice note controller.
parent
d06c633d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/org/thoughtcrime/securesms/components/voice/VoiceNoteMediaController.java
+54
-1
54 additions, 1 deletion
.../securesms/components/voice/VoiceNoteMediaController.java
with
54 additions
and
1 deletion
app/src/main/java/org/thoughtcrime/securesms/components/voice/VoiceNoteMediaController.java
+
54
−
1
View file @
98fc3e5b
...
...
@@ -145,7 +145,7 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
return
playbackStateCompat
.
getState
()
<=
PlaybackStateCompat
.
STATE_STOPPED
;
}
private
@N
onN
ull
MediaControllerCompat
getMediaController
()
{
private
@Null
able
MediaControllerCompat
getMediaController
()
{
return
MediaControllerCompat
.
getMediaController
(
activity
);
}
...
...
@@ -172,6 +172,11 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
* @param singlePlayback The player will only play back the specified Uri, and not build a playlist.
*/
private
void
startPlayback
(
@NonNull
Uri
audioSlideUri
,
long
messageId
,
long
threadId
,
double
progress
,
boolean
singlePlayback
)
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called startPlayback before controller was set. ("
+
getActivityName
()
+
")"
);
return
;
}
if
(
isCurrentTrack
(
audioSlideUri
))
{
long
duration
=
getMediaController
().
getMetadata
().
getLong
(
MediaMetadataCompat
.
METADATA_KEY_DURATION
);
...
...
@@ -196,6 +201,11 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
* @param messageId The Message id of the given audio slide
*/
public
void
resumePlayback
(
@NonNull
Uri
audioSlideUri
,
long
messageId
)
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called resumePlayback before controller was set. ("
+
getActivityName
()
+
")"
);
return
;
}
if
(
isCurrentTrack
(
audioSlideUri
))
{
getMediaController
().
getTransportControls
().
play
();
}
else
{
...
...
@@ -215,6 +225,11 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
* @param audioSlideUri The Uri of the audio slide to pause.
*/
public
void
pausePlayback
(
@NonNull
Uri
audioSlideUri
)
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called pausePlayback(uri) before controller was set. ("
+
getActivityName
()
+
")"
);
return
;
}
if
(
isCurrentTrack
(
audioSlideUri
))
{
getMediaController
().
getTransportControls
().
pause
();
}
...
...
@@ -224,6 +239,11 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
* Pauses playback regardless of which audio slide is playing.
*/
public
void
pausePlayback
()
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called pausePlayback before controller was set. ("
+
getActivityName
()
+
")"
);
return
;
}
getMediaController
().
getTransportControls
().
pause
();
}
...
...
@@ -235,6 +255,11 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
* @param progress The progress percentage to seek to.
*/
public
void
seekToPosition
(
@NonNull
Uri
audioSlideUri
,
double
progress
)
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called seekToPosition before controller was set. ("
+
getActivityName
()
+
")"
);
return
;
}
if
(
isCurrentTrack
(
audioSlideUri
))
{
long
duration
=
getMediaController
().
getMetadata
().
getLong
(
MediaMetadataCompat
.
METADATA_KEY_DURATION
);
...
...
@@ -250,12 +275,22 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
* @param audioSlideUri The Uri of the audio slide to stop
*/
public
void
stopPlaybackAndReset
(
@NonNull
Uri
audioSlideUri
)
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called stopPlaybackAndReset before controller was set. ("
+
getActivityName
()
+
")"
);
return
;
}
if
(
isCurrentTrack
(
audioSlideUri
))
{
getMediaController
().
getTransportControls
().
stop
();
}
}
public
void
setPlaybackSpeed
(
@NonNull
Uri
audioSlideUri
,
float
playbackSpeed
)
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called setPlaybackSpeed before controller was set. ("
+
getActivityName
()
+
")"
);
return
;
}
if
(
isCurrentTrack
(
audioSlideUri
))
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putFloat
(
VoiceNotePlaybackService
.
ACTION_NEXT_PLAYBACK_SPEED
,
playbackSpeed
);
...
...
@@ -265,12 +300,22 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
}
private
boolean
isCurrentTrack
(
@NonNull
Uri
uri
)
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called isCurrentTrack before controller was set. ("
+
getActivityName
()
+
")"
);
return
false
;
}
MediaMetadataCompat
metadataCompat
=
getMediaController
().
getMetadata
();
return
metadataCompat
!=
null
&&
Objects
.
equals
(
metadataCompat
.
getDescription
().
getMediaUri
(),
uri
);
}
private
void
notifyProgressEventHandler
()
{
if
(
getMediaController
()
==
null
)
{
Log
.
w
(
TAG
,
"Called notifyProgressEventHandler before controller was set. ("
+
getActivityName
()
+
")"
);
return
;
}
if
(
progressEventHandler
==
null
&&
activity
!=
null
)
{
progressEventHandler
=
new
ProgressEventHandler
(
getMediaController
(),
voiceNotePlaybackState
);
progressEventHandler
.
sendEmptyMessage
(
0
);
...
...
@@ -283,6 +328,14 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
}
}
private
@NonNull
String
getActivityName
()
{
if
(
activity
==
null
)
{
return
"Activity is null"
;
}
else
{
return
activity
.
getLocalClassName
();
}
}
private
final
class
ConnectionCallback
extends
MediaBrowserCompat
.
ConnectionCallback
{
@Override
public
void
onConnected
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment