Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PlayWallDesktop
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PlayWall
PlayWallDesktop
Commits
fc9957b2
Commit
fc9957b2
authored
8 years ago
by
tobias
Browse files
Options
Downloads
Patches
Plain Diff
Add Position Thread
parent
8cd0e5eb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
PlayWallNative/src/de/tobias/playpad/NativeAudioMacHandler.java
+71
-2
71 additions, 2 deletions
...llNative/src/de/tobias/playpad/NativeAudioMacHandler.java
with
71 additions
and
2 deletions
PlayWallNative/src/de/tobias/playpad/NativeAudioMacHandler.java
+
71
−
2
View file @
fc9957b2
package
de.tobias.playpad
;
import
java.nio.file.Path
;
import
java.util.ArrayList
;
import
java.util.ConcurrentModificationException
;
import
java.util.Iterator
;
import
java.util.List
;
import
de.tobias.playpad.audio.AudioHandler
;
import
de.tobias.playpad.pad.PadStatus
;
import
de.tobias.playpad.pad.conntent.PadContent
;
import
de.tobias.utils.util.Worker
;
import
javafx.application.Platform
;
import
javafx.beans.property.ObjectProperty
;
import
javafx.beans.property.ReadOnlyObjectProperty
;
import
javafx.beans.property.SimpleObjectProperty
;
...
...
@@ -13,6 +18,8 @@ import javafx.util.Duration;
public
class
NativeAudioMacHandler
extends
AudioHandler
{
private
static
final
int
SLEEP_TIME_POSITION
=
100
;
private
static
int
counter
=
0
;
private
final
int
id
;
...
...
@@ -20,6 +27,39 @@ public class NativeAudioMacHandler extends AudioHandler {
private
ObjectProperty
<
Duration
>
durationProperty
;
private
boolean
isLoaded
;
private
static
Thread
positionThread
;
private
static
List
<
NativeAudioMacHandler
>
playedHandlers
=
new
ArrayList
<>();
static
{
positionThread
=
new
Thread
(()
->
{
while
(
true
)
{
try
{
if
(
playedHandlers
.
isEmpty
())
{
synchronized
(
positionThread
)
{
positionThread
.
wait
();
}
}
for
(
Iterator
<
NativeAudioMacHandler
>
iterator
=
playedHandlers
.
iterator
();
iterator
.
hasNext
();)
{
NativeAudioMacHandler
handler
=
iterator
.
next
();
Duration
seconds
=
Duration
.
seconds
(
NativeAudio
.
getPosition
(
handler
.
id
));
Platform
.
runLater
(()
->
handler
.
positionProperty
.
set
(
seconds
));
}
Thread
.
sleep
(
SLEEP_TIME_POSITION
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
ConcurrentModificationException
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
});
positionThread
.
start
();
}
public
NativeAudioMacHandler
(
PadContent
content
)
{
super
(
content
);
...
...
@@ -31,16 +71,33 @@ public class NativeAudioMacHandler extends AudioHandler {
@Override
public
void
play
()
{
NativeAudio
.
play
(
id
);
boolean
start
=
false
;
if
(
playedHandlers
.
isEmpty
())
{
start
=
true
;
}
if
(!
playedHandlers
.
contains
(
this
))
playedHandlers
.
add
(
this
);
if
(
start
)
{
synchronized
(
positionThread
)
{
positionThread
.
notify
();
}
}
}
@Override
public
void
pause
()
{
NativeAudio
.
pause
(
id
);
if
(
playedHandlers
.
contains
(
this
))
playedHandlers
.
remove
(
this
);
}
@Override
public
void
stop
()
{
NativeAudio
.
stop
(
id
);
if
(
playedHandlers
.
contains
(
this
))
playedHandlers
.
remove
(
this
);
}
@Override
...
...
@@ -77,12 +134,24 @@ public class NativeAudioMacHandler extends AudioHandler {
@Override
public
void
loadMedia
(
Path
[]
paths
)
{
Platform
.
runLater
(()
->
{
if
(
getContent
().
getPad
().
isPadVisible
())
{
getContent
().
getPad
().
getController
().
getView
().
showBusyView
(
true
);
}
});
Worker
.
runLater
(()
->
{
isLoaded
=
NativeAudio
.
load
(
id
,
paths
[
0
].
toString
().
replace
(
" "
,
"%20"
));
if
(
isLoaded
)
{
Platform
.
runLater
(()
->
{
durationProperty
.
set
(
Duration
.
seconds
(
NativeAudio
.
getDuration
(
id
)));
getContent
().
getPad
().
setStatus
(
PadStatus
.
READY
);
if
(
getContent
().
getPad
().
isPadVisible
())
{
getContent
().
getPad
().
getController
().
getView
().
showBusyView
(
false
);
}
});
}
});
}
...
...
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