Getting a sound/musics time in PCM samples?

I’d like to get a sound or music’s time in samples instead of milliseconds. Something like the timeSamples variable in unity. How can this be achieved?

can you provide more information? we dont know how to help you if you dont specify with what you’re playing audio with

also im pretty sure that you’re able to extract the samples passed from the milisecond data if you have the sample rate of the audio. for example, CD-DA quality audio will play 44100 samples a second, meaning that 88200 samples play in two seconds so on and on… meaning if you just take your milisecond value, divide it by 1000 to get the second value and multiply it by the sampele rate and that should be the ammount of samples that have been played.
my math may be wrong so if it is just ignore that i said any of this