<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Sorry for double-post; I think my fist attempt got blocked because I wasn’t subscribed.<o:p></o:p></p>
<p class="MsoNormal">Also sorry if this is the wrong list; please redirect me if so.<o:p></o:p></p>
<p class="MsoNormal">ALSO ALSO sorry if this is a bit of a disorganized rant, but I’m a bit frustrated.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Suppose I have a sound file on my hard disk and want Java to play it.<o:p></o:p></p>
<p class="MsoNormal">By copying random code snippets off the internet, we can discover<o:p></o:p></p>
<p class="MsoNormal">sun.audio.AudioPlayer.player.start(java.io.InputStream file)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Easy! But wait, the sun.* packages are not officially exported and javac 8 complains, and with modules it likely complains even louder.<o:p></o:p></p>
<p class="MsoNormal">Then we discover JavaFX has a nifty MediaPlayer which is almost as easy. But JavaFX is “de-bundled” so that’s a bit annoying.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">No matter, we can use Applet.newAudioClip()! We don’t want an applet, this API works fine without them. Nice!<o:p></o:p></p>
<p class="MsoNormal">But the entire applet namespace is deprecated, and even worse, it is deprecated for removal.<o:p></o:p></p>
<p class="MsoNormal">(For the record, I think deprecating it makes sense, but deprecating it for removal was a bad idea and should be undone. But I’m an outsider, so whatever.)<o:p></o:p></p>
<p class="MsoNormal">Depending on things that are threatened to go away on possibly short notice seems risky, so let’s not.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I see something called JMF (Java Media Framework) but that’s also not bundled, and hard to even find docs for. Sigh.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Let’s looks at something nice and official: the sound tutorial:<o:p></o:p></p>
<p class="MsoNormal"><a href="https://docs.oracle.com/javase/tutorial/sound/playing.html">https://docs.oracle.com/javase/tutorial/sound/playing.html</a><o:p></o:p></p>
<p class="MsoNormal">Oh dear, that looks complicated. I guess we need to somehow get Clip? How to do that?<o:p></o:p></p>
<p class="MsoNormal">The tutorial has a big warning on top that it hasn’t been updated since Java 8 but I suspect it hasn’t been touched since Java 5 or longer.<o:p></o:p></p>
<p class="MsoNormal">Well, in must have been touched a bit, since it uses Clip.class syntax which was added in Java 5. But what it doesn’t have is any mention of these methods:<o:p></o:p></p>
<p class="MsoNormal"><a href="https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4896221">https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4896221</a><o:p></o:p></p>
<p class="MsoNormal">My best explanation is that they got added after the tutorial was written, and then the tutorial was never updated, which I think reduces the amount of good those methods do.<o:p></o:p></p>
<p class="MsoNormal">But that’s okay because we found those methods, one of which is called getClip(). Yay, we have Clip!<o:p></o:p></p>
<p class="MsoNormal">Now all we need to do is clip.open(AudioInputStream)… hmm. Where do I get one of those? The tutorial doesn’t seem to say.<o:p></o:p></p>
<p class="MsoNormal">The official Javadocs have a neat feature where each interface lists all public classes that implement it.<o:p></o:p></p>
<p class="MsoNormal">What it does NOT have is a list of all methods whose return type “matches” the interface.<o:p></o:p></p>
<p class="MsoNormal">But that’s okay, we have nice IDEs, so I can just “find usages” of AudioInputStream and filter down to those where it appears as a return type!<o:p></o:p></p>
<p class="MsoNormal">And there we go: I need AudioSystem.getAudioInputStream().<o:p></o:p></p>
<p class="MsoNormal">And then we’re ready: we can call start() and it will play our clip!<o:p></o:p></p>
<p class="MsoNormal">Hmm… I wonder if the call returns when playback starts or only when it ends… maybe we need a scratch thread so it doesn’t block us?<o:p></o:p></p>
<p class="MsoNormal">Oh and let’s not forget to close() the clip when we’re done!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This API seems to try pretty hard to give experts everything they need.<o:p></o:p></p>
<p class="MsoNormal">But it doesn’t cater very well to the use case of “I don’t know what a mixer is, and I wish I didn’t have to care!”<o:p></o:p></p>
<p class="MsoNormal">The highly-nonofficial sun.audio.AudioPlayer does a pretty good job for this use-case; there should ideally be something at LEAST that easy in an official, non-deprecated API.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Just my two cents.<o:p></o:p></p>
<p class="MsoNormal">Mark<o:p></o:p></p>
</div>
<P><SPAN lang=EN-US style="mso-ansi-language: EN-US">This message is for
information purposes only. It is not a recommendation, advice, offer or
solicitation to buy or sell a product or service, nor an official confirmation
of any transaction. It is directed at persons who are professionals and is
intended for the recipient(s) only. It is not directed at retail customers. This
message is subject to the terms at: <A
href="https://www.cib.barclays/disclosures/web-and-email-disclaimer.html">https://www.cib.barclays/disclosures/web-and-email-disclaimer.html</A>.
</SPAN></P>
<P><SPAN lang=EN-US style="mso-ansi-language: EN-US">For important disclosures,
please see: <A
href="https://www.cib.barclays/disclosures/sales-and-trading-disclaimer.html">https://www.cib.barclays/disclosures/sales-and-trading-disclaimer.html</A>
regarding marketing commentary from Barclays Sales and/or Trading desks, who are
active market participants; <A
href="https://www.cib.barclays/disclosures/barclays-global-markets-disclosures.html">https://www.cib.barclays/disclosures/barclays-global-markets-disclosures.html</A>
regarding our standard terms for Barclays Corporate and Investment Bank where we
trade with you in principal-to-principal wholesale markets transactions; and in
respect to Barclays Research, including disclosures relating to specific
issuers, see: <A
href="http://publicresearch.barclays.com">http://publicresearch.barclays.com</A>.<BR>__________________________________________________________________________________
<BR>If you are incorporated or operating in Australia, read these important
disclosures: <A
href="https://www.cib.barclays/disclosures/important-disclosures-asia-pacific.html">https://www.cib.barclays/disclosures/important-disclosures-asia-pacific.html</A>.<BR>__________________________________________________________________________________<BR>For
more details about how we use personal information, see our privacy notice: <A
href="https://www.cib.barclays/disclosures/personal-information-use.html">https://www.cib.barclays/disclosures/personal-information-use.html</A>.
<BR>__________________________________________________________________________________<BR></O:P></SPAN></P>
</body>
</html>