Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
NUI
TULIP-Scenario
Commits
dfdc3b8f
Commit
dfdc3b8f
authored
Oct 06, 2016
by
Valérie Maquil
Browse files
sounds can be loaded as base64
parent
29066317
Changes
1
Show whitespace changes
Inline
Side-by-side
Scenarios/src/lu/list/itis/dkd/tui/scenario/Scene.java
View file @
dfdc3b8f
...
@@ -75,6 +75,8 @@ public class Scene extends Content {
...
@@ -75,6 +75,8 @@ public class Scene extends Content {
/** The sound to play when painting. */
/** The sound to play when painting. */
private
Clip
audioClip
;
private
Clip
audioClip
;
private
boolean
triggered
=
false
;
private
boolean
triggered
=
false
;
private
AudioInputStream
audioIn
;
private
AudioInputStream
audioStream
;
/**
/**
* Constructor initializing all fields.
* Constructor initializing all fields.
...
@@ -123,9 +125,9 @@ public class Scene extends Content {
...
@@ -123,9 +125,9 @@ public class Scene extends Content {
try
{
try
{
final
Element
imageBase64Node
=
element
.
getChild
(
Externalization
.
IMAGE_BASE64_ELEMENT
);
final
Element
imageBase64Node
=
element
.
getChild
(
Externalization
.
IMAGE_BASE64_ELEMENT
);
if
((
null
!=
imageBase64Node
)
&&
(
imageBase64Node
.
getText
()
!=
""
))
{
if
((
null
!=
imageBase64Node
)
&&
(
imageBase64Node
.
getText
()
!=
""
))
{
//$NON-NLS-1$
final
String
[]
tokens
=
(
imageBase64Node
.
getText
()).
split
(
","
);
final
String
[]
tokens
=
(
imageBase64Node
.
getText
()).
split
(
","
);
//$NON-NLS-1$
System
.
out
.
println
(
tokens
[
1
]);
//
System.out.println(tokens[1]);
byte
[]
imageByte
;
byte
[]
imageByte
;
imageByte
=
Base64
.
getDecoder
().
decode
(
tokens
[
1
]);
imageByte
=
Base64
.
getDecoder
().
decode
(
tokens
[
1
]);
final
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
imageByte
);
final
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
imageByte
);
...
@@ -138,9 +140,9 @@ public class Scene extends Content {
...
@@ -138,9 +140,9 @@ public class Scene extends Content {
try
{
try
{
final
Element
soundNode
=
element
.
getChild
(
Externalization
.
SOUND_NODE
);
final
Element
soundNode
=
element
.
getChild
(
Externalization
.
SOUND_NODE
);
if
((
null
!=
soundNode
)
&&
(
soundNode
.
getText
()
!=
""
))
{
if
((
null
!=
soundNode
)
&&
(
soundNode
.
getText
()
!=
""
))
{
//$NON-NLS-1$
final
File
audioFile
=
new
File
(
soundNode
.
getText
());
final
File
audioFile
=
new
File
(
soundNode
.
getText
());
final
AudioInputStream
audioStream
=
AudioSystem
.
getAudioInputStream
(
audioFile
);
audioStream
=
AudioSystem
.
getAudioInputStream
(
audioFile
);
final
AudioFormat
format
=
audioStream
.
getFormat
();
final
AudioFormat
format
=
audioStream
.
getFormat
();
final
DataLine
.
Info
info
=
new
DataLine
.
Info
(
Clip
.
class
,
format
);
final
DataLine
.
Info
info
=
new
DataLine
.
Info
(
Clip
.
class
,
format
);
audioClip
=
(
Clip
)
AudioSystem
.
getLine
(
info
);
audioClip
=
(
Clip
)
AudioSystem
.
getLine
(
info
);
...
@@ -149,7 +151,7 @@ public class Scene extends Content {
...
@@ -149,7 +151,7 @@ public class Scene extends Content {
}
}
catch
(
final
FileNotFoundException
e
)
{
catch
(
final
FileNotFoundException
e
)
{
throw
new
BuildException
(
"The file could not be found!"
,
e
);
//$NON-NLS-1$
//
throw new BuildException("The file could not be found!", e); //$NON-NLS-1$
}
catch
(
final
IOException
e
)
{
}
catch
(
final
IOException
e
)
{
throw
new
BuildException
(
"The sound could not be read!"
,
e
);
//$NON-NLS-1$
throw
new
BuildException
(
"The sound could not be read!"
,
e
);
//$NON-NLS-1$
}
catch
(
final
UnsupportedAudioFileException
e
)
{
}
catch
(
final
UnsupportedAudioFileException
e
)
{
...
@@ -159,7 +161,25 @@ public class Scene extends Content {
...
@@ -159,7 +161,25 @@ public class Scene extends Content {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
try
{
final
Element
soundBase64Node
=
element
.
getChild
(
Externalization
.
SOUND_BASE64_NODE
);
if
((
null
!=
soundBase64Node
)
&&
(
soundBase64Node
.
getText
()
!=
""
))
{
//$NON-NLS-1$
final
String
[]
tokens
=
(
soundBase64Node
.
getText
()).
split
(
","
);
//$NON-NLS-1$
// System.out.println(tokens[1]);
final
byte
[]
soundByte
=
Base64
.
getDecoder
().
decode
(
tokens
[
1
]);
audioIn
=
AudioSystem
.
getAudioInputStream
(
new
ByteArrayInputStream
(
soundByte
));
audioClip
=
AudioSystem
.
getClip
();
audioClip
.
open
(
audioIn
);
}
}
catch
(
final
UnsupportedAudioFileException
e
)
{
throw
new
BuildException
(
"The sound format is not supported!"
,
e
);
//$NON-NLS-1$
}
catch
(
final
IOException
e
)
{
throw
new
BuildException
(
"The sound could not be read!"
,
e
);
//$NON-NLS-1$
}
catch
(
final
LineUnavailableException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment