1

at the moment my code is like this

echo '<script type="text/javascript">';
echo '<audio id="player" src="../cdh/ba1.mp3">';
echo '</script>';   
echo '<a onclick="playAudio();"><i class=\'fa fa-lg fa-volume-up\'></i></a>';
echo '<script type="text/javascript">';
echo 'function playAudio(){var audio = new Audio("../cdh/ba1.mp3");';
echo 'audio.play();}';
echo '</script>';

I want to get my src="..." & var audio = ... working with a php variable I have. I have variable $row0['PIN'] which is the exact same as its filename - $row0['PIN'] is made up of Chinese pinyin so things like ba1 and ba1 jia1.

How can I do this?

1 Answer 1

1

Try this

$audio_file = $row['PIN']; 
$audio_path = "../cdh/$audio_file.mp3"; 
echo '<a onclick="playAudio(\''.$audio_path.'\');"><i class=\'fa fa-lg fa-volume-up\'></i></a>'; 
echo '<script type="text/javascript">'; 
echo 'function playAudio(path){var audio = new Audio(path);'; 
echo 'audio.play();}'; 
echo '</script>';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.