cordova-plugin-media my_media is not defined

Does anyone know how to use cordova-plugin-media ?

I've followed the documentation and I am able to get it to play a file but when I call my_media.stop() I get the error 'Uncaught ReferenceError: my_media is not defined'

This is happening for pause() also. I have a function that gets the tracks position and this will work if placed within the play function but not if outside of the function, same issue ,'Uncaught ReferenceError: my_media is not defined'

Here is my code. Any help very much appreciated.

 var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');    

function playAudio(url) {
    // Play the audio file at url
    var my_media = new Media(url,
        // success callback
        function () {
            console.log("playAudio():Audio Success");
        },
        // error callback
        function (err) {
            console.log("playAudio():Audio Error: " + err);
        }
    );
    // Play audio
    my_media.play();
}
$('#pausebutton').click(function() {
 my_media.pause();
});
$('#stopbutton').click(function() {
 my_media.stop();
});

// Update media position every second
var mediaTimer = setInterval(function () {
    // get media position
    my_media.getCurrentPosition(
        // success callback
        function (position) {
            if (position > -1) {
                console.log((position) + " sec");
            }
        },
        // error callback
        function (e) {
            console.log("Error getting pos=" + e);
        }
    );
}, 1000);
$(document).on('click', '.play', function() {
playfile = $(this).attr("value");
console.log("play "+playfile)
playAudio(playfile);
});
},