<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=utf-8">
<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:blue;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle21
{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;}
/* List Definitions */
@list l0
{mso-list-id:882597214;
mso-list-type:hybrid;
mso-list-template-ids:-469191930 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
--></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="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Thanks for raising that. Since I can’t comment on that issue directly, let me respond here to the claim by Alex Z. that “it’s not so bad”:<o:p></o:p></p>
<p class="MsoNormal">I agree that the code snippet he posted doesn’t look too bad, at least for the async case.<o:p></o:p></p>
<p class="MsoNormal">But!! Consider the following:<o:p></o:p></p>
<ol style="margin-top:0in" start="1" type="1">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l0 level1 lfo1">We never closed the stream. Is this “fine” or are we leaking an OS file handle?<o:p></o:p></li></ol>
<p class="MsoListParagraph">We also never closed the clip. Who knows what that leaks? Maybe a thread or two?<o:p></o:p></p>
<p class="MsoListParagraph">(If we need not close these, the docs should make that clearer; I think we do.)<o:p></o:p></p>
<p class="MsoListParagraph">I see the JDK code has a concept of an auto-closing clip but the docs don’t mention it.<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">2.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]>But of course, we can’t close the clip or the stream, or else playback ends.<o:p></o:p></p>
<p class="MsoListParagraph">Thus we must wait for it to finish. So the whole async approach is not viable.<o:p></o:p></p>
<p class="MsoListParagraph">The REAL way to do async is to actually to do sync, but on another thread.<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">3.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]>So how do we do sync then? The example code by Alex Z uses busy looping.<o:p></o:p></p>
<p class="MsoListParagraph">Nice and simple for short clips, but pretty rude if the clip lasts more than a few seconds.<o:p></o:p></p>
<p class="MsoListParagraph">Easy fix:<o:p></o:p></p>
<p class="MsoListParagraph">try{Thread.sleep(clip. getMicrosecondLength/1000);}<o:p></o:p></p>
<p class="MsoListParagraph">catch(InterruptedException impossible){Thread.currentThread.interrupt();}<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">4.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]>This works for .wav files but not some of the more obscure file types that Java supports.<o:p></o:p></p>
<p class="MsoListParagraph">(In fact I don’t think it’s even guaranteed to work for ALL wav files.)<o:p></o:p></p>
<p class="MsoListParagraph">It works only for files encoded using PCM.<o:p></o:p></p>
<p class="MsoListParagraph">If you try to open a .au file, you’ll likely get an exception during playback.<o:p></o:p></p>
<p class="MsoListParagraph">To support EVERYTHING, we need to basically copy/paste the implementation of<o:p></o:p></p>
<p class="MsoListParagraph">com.sun.media.sound.Toolkit#getPCMConvertedAudioInputStream<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Not so simple any more.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Philip Race <philip.race@oracle.com> <br>
<b>Sent:</b> Monday, January 8, 2024 3:05 PM<br>
<b>To:</b> Yagnatinsky, Mark : Markets Pre Trade <mark.yagnatinsky@barclays.com>; mickleness@gmail.com<br>
<b>Cc:</b> client-libs-dev@openjdk.org<br>
<b>Subject:</b> Re: the easiest ways to play an audio clip are the discouraged ones<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p><span style="font-size:12.0pt;color:#010101">CAUTION: This email originated from outside our organisation -
<a href="mailto:philip.race@oracle.com">philip.race@oracle.com</a> Do not click on links, open attachments, or respond unless you recognize the sender and can validate the content is safe.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">Mark,<br>
<br>
It does seem like there's an ease of use gap here that will widen considerably when Applet is removed.<br>
The Applet AudioClip code is actually built on top of javax.sound public APIs so we should at least<br>
find an alternative place to surface that functionality.<br>
I submitted <a href="https://clicktime.symantec.com/15t5ejgC3n4Z2qVqt9Uzx?h=KL29DCPORvn7BrJRUY9MkcWCJvOw3Ti8Sa0X4iwSGd0=&u=https://bugs.openjdk.org/browse/JDK-8323215">
https://bugs.openjdk.org/browse/JDK-8323215</a><br>
<br>
-phil.<br>
<br>
<o:p></o:p></p>
<div>
<p class="MsoNormal">On 1/1/24 10:27 PM, <a href="mailto:mark.yagnatinsky@barclays.com">
mark.yagnatinsky@barclays.com</a> wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Thanks Julian (and sorry for messing up the message threading… I’ll try not to do that next time).<o:p></o:p></p>
<p class="MsoNormal">It looks like you built a “full-fledged” audio player, and it took hundreds of lines of code.<o:p></o:p></p>
<p class="MsoNormal">Maybe that’s reasonable for a full-fledged audio player.<o:p></o:p></p>
<p class="MsoNormal">But it’s unfortunate that even a basic “fire and forget” feature to play an audio file should take lots of lines.<o:p></o:p></p>
<p>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://clicktime.symantec.com/15t64tecLrUX6ZdTbwUk4?h=zTRoMouG9T7J9FQL4cV94e4LpmXd0QBPgRcPiFYhyoY=&u=https://www.cib.barclays/disclosures/web-and-email-disclaimer.html">
https://www.cib.barclays/disclosures/web-and-email-disclaimer.html</a>. <o:p></o:p></p>
<p>For important disclosures, please see: <a href="https://clicktime.symantec.com/15t5z4TKtEnvgcoY4P5bS?h=767BC8a5NeiFe_svD-4V0rH6-HZDQlmjy_NpsCW3aWg=&u=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://clicktime.symantec.com/15t5jZsUWPk9SnKmRht9a?h=tWdXvcM5kHrxpBVJQFk6rFm-MMccVjO3NPCn5xX4XSU=&u=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="https://clicktime.symantec.com/15t5ZuUubANxctfvLb5rL?h=dkT0VoD4Dt7QFIniMdDidoMGx1LcjPlaNUkOocHfWgs=&u=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://clicktime.symantec.com/15t5pQ4ky1Rjrj9gyGHJC?h=932YgECPl7OZfrEzAA2cyxVWM1zo51MwACmHOzOspAw=&u=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://clicktime.symantec.com/15t5uEG3Rd7LGfycWpgSp?h=oODbdUzOo6E0nPTwfje85bWWFNKbWeln9i_9WMFcWhk=&u=https://www.cib.barclays/disclosures/personal-information-use.html">
https://www.cib.barclays/disclosures/personal-information-use.html</a>. <br>
__________________________________________________________________________________<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><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>