Created
August 4, 2012 14:54
-
-
Save uzulla/3258224 to your computer and use it in GitHub Desktop.
iTunes affiliate search API + Audio tag Player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<html> | |
<head> | |
<title>iTunes affiliate search API + Audio tag Player</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
</head> | |
<body> | |
<h1>iTunes affiliate search API+ Audio tag Player</h1> | |
<script> | |
function load(){ | |
$.ajax({ | |
url:"http://itunes.apple.com/search", | |
data:{term:$('#keyword').val(),entity:"song"}, | |
type:"GET", | |
dataType: "jsonp", | |
success: function(data, dataType){ | |
console.log(data); | |
var results = data.results; | |
var imgurl = results[0]['artworkUrl100']; | |
var mediaurl = results[0]['previewUrl']; | |
$('#artwork').attr('src', imgurl); | |
$('#audio').attr('src', mediaurl); | |
} | |
}) | |
} | |
function play(){ | |
$('#audio')[0].play(); | |
} | |
function stop(){ | |
$('#audio')[0].pause(); | |
} | |
</script> | |
<input type="text" value="daft punk" id="keyword"> | |
<input type="button" value="load" onclick="load()"> | |
<input type="button" value="play" onclick="play()"> | |
<input type="button" value="stop" onclick="stop()"> | |
<br> | |
<audio id="audio"></audio> | |
<img id="artwork" width="100" height="100"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment