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”:
I agree that the code snippet he posted doesn’t look too bad, at least for the 
async case.
But!!  Consider the following:

  1.  We never closed the stream.  Is this “fine” or are we leaking an OS file 
handle?

We also never closed the clip.  Who knows what that leaks?  Maybe a thread or 
two?

(If we need not close these, the docs should make that clearer; I think we do.)

I see the JDK code has a concept of an auto-closing clip but the docs don’t 
mention it.

2.       But of course, we can’t close the clip or the stream, or else playback 
ends.

Thus we must wait for it to finish.  So the whole async approach is not viable.

The REAL way to do async is to actually to do sync, but on another thread.

3.       So how do we do sync then?  The example code by Alex Z uses busy 
looping.

Nice and simple for short clips, but pretty rude if the clip lasts more than a 
few seconds.

Easy fix:

try{Thread.sleep(clip. getMicrosecondLength/1000);}

catch(InterruptedException impossible){Thread.currentThread.interrupt();}

4.       This works for .wav files but not some of the more obscure file types 
that Java supports.

(In fact I don’t think it’s even guaranteed to work for ALL wav files.)

It works only for files encoded using PCM.

If you try to open a .au file, you’ll likely get an exception during playback.

To support EVERYTHING, we need to basically copy/paste the implementation of

com.sun.media.sound.Toolkit#getPCMConvertedAudioInputStream

Not so simple any more.

From: Philip Race <philip.r...@oracle.com>
Sent: Monday, January 8, 2024 3:05 PM
To: Yagnatinsky, Mark : Markets Pre Trade <mark.yagnatin...@barclays.com>; 
micklen...@gmail.com
Cc: client-libs-dev@openjdk.org
Subject: Re: the easiest ways to play an audio clip are the discouraged ones


CAUTION: This email originated from outside our organisation - 
philip.r...@oracle.com<mailto:philip.r...@oracle.com> Do not click on links, 
open attachments, or respond unless you recognize the sender and can validate 
the content is safe.
Mark,

It does seem like there's an ease of use gap here that will widen considerably 
when Applet is removed.
The Applet  AudioClip code is actually built on top of javax.sound public APIs 
so we should at least
find an alternative place to surface that functionality.
I submitted 
https://bugs.openjdk.org/browse/JDK-8323215<https://clicktime.symantec.com/15t5ejgC3n4Z2qVqt9Uzx?h=KL29DCPORvn7BrJRUY9MkcWCJvOw3Ti8Sa0X4iwSGd0=&u=https://bugs.openjdk.org/browse/JDK-8323215>

-phil.

On 1/1/24 10:27 PM, 
mark.yagnatin...@barclays.com<mailto:mark.yagnatin...@barclays.com> wrote:
Thanks Julian (and sorry for messing up the message threading… I’ll try not to 
do that next time).
It looks like you built a “full-fledged” audio player, and it took hundreds of 
lines of code.
Maybe that’s reasonable for a full-fledged audio player.
But it’s unfortunate that even a basic “fire and forget” feature to play an 
audio file should take lots of lines.

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: 
https://www.cib.barclays/disclosures/web-and-email-disclaimer.html<https://clicktime.symantec.com/15t64tecLrUX6ZdTbwUk4?h=zTRoMouG9T7J9FQL4cV94e4LpmXd0QBPgRcPiFYhyoY=&u=https://www.cib.barclays/disclosures/web-and-email-disclaimer.html>.

For important disclosures, please see: 
https://www.cib.barclays/disclosures/sales-and-trading-disclaimer.html<https://clicktime.symantec.com/15t5z4TKtEnvgcoY4P5bS?h=767BC8a5NeiFe_svD-4V0rH6-HZDQlmjy_NpsCW3aWg=&u=https://www.cib.barclays/disclosures/sales-and-trading-disclaimer.html>
 regarding marketing commentary from Barclays Sales and/or Trading desks, who 
are active market participants; 
https://www.cib.barclays/disclosures/barclays-global-markets-disclosures.html<https://clicktime.symantec.com/15t5jZsUWPk9SnKmRht9a?h=tWdXvcM5kHrxpBVJQFk6rFm-MMccVjO3NPCn5xX4XSU=&u=https://www.cib.barclays/disclosures/barclays-global-markets-disclosures.html>
 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: 
http://publicresearch.barclays.com<https://clicktime.symantec.com/15t5ZuUubANxctfvLb5rL?h=dkT0VoD4Dt7QFIniMdDidoMGx1LcjPlaNUkOocHfWgs=&u=http://publicresearch.barclays.com>.
__________________________________________________________________________________
If you are incorporated or operating in Australia, read these important 
disclosures: 
https://www.cib.barclays/disclosures/important-disclosures-asia-pacific.html<https://clicktime.symantec.com/15t5pQ4ky1Rjrj9gyGHJC?h=932YgECPl7OZfrEzAA2cyxVWM1zo51MwACmHOzOspAw=&u=https://www.cib.barclays/disclosures/important-disclosures-asia-pacific.html>.
__________________________________________________________________________________
For more details about how we use personal information, see our privacy notice: 
https://www.cib.barclays/disclosures/personal-information-use.html<https://clicktime.symantec.com/15t5uEG3Rd7LGfycWpgSp?h=oODbdUzOo6E0nPTwfje85bWWFNKbWeln9i_9WMFcWhk=&u=https://www.cib.barclays/disclosures/personal-information-use.html>.
__________________________________________________________________________________


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: 
https://www.cib.barclays/disclosures/web-and-email-disclaimer.html. 

For important disclosures, please see: 
https://www.cib.barclays/disclosures/sales-and-trading-disclaimer.html 
regarding marketing commentary from Barclays Sales and/or Trading desks, who 
are active market participants; 
https://www.cib.barclays/disclosures/barclays-global-markets-disclosures.html 
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: http://publicresearch.barclays.com.
__________________________________________________________________________________
 
If you are incorporated or operating in Australia, read these important 
disclosures: 
https://www.cib.barclays/disclosures/important-disclosures-asia-pacific.html.
__________________________________________________________________________________
For more details about how we use personal information, see our privacy notice: 
https://www.cib.barclays/disclosures/personal-information-use.html. 
__________________________________________________________________________________

Reply via email to