1

I have two angularJS $scope functions inside a main one. When calling the play() function there is an error stating that getPhoneGapPath() is undefined. What is the solution to this

My Code:

function DontAsk($scope){
$scope.getPhoneGapPath = function(){

    var path = window.location.pathname;
    path = path.substr( 0, path.length - 10 );
    return 'file://' + path;

}
$scope.play= function(){
    var os = navigator.platform;
    if (os=='iPhone'){
        var url = "sounds/DontEventAsk.mp3";
    }
    else{
        var url = getPhoneGapPath() + "sounds/DontEventAsk.mp3";
    }
    var my_media = new Media(url,
        // success callback
        function() {
            console.log("playAudio():Audio Success");
        },
        // error callback
        function(err) {
            console.log("playAudio():Audio Error: "+JSON.stringify(err));
    });

    // Play audio
    my_media.play();
}}

Ideally I would want the getPhoneGapPath() to be defined and also outside the main function because I have multiple functions like the DontAsk() one.

Thanks a lot.

2 Answers 2

2
var url = $scope.getPhoneGapPath() + "sounds/DontEventAsk.mp3";
Sign up to request clarification or add additional context in comments.

Comments

1

There is no getPhoneGapPath function in the scope. You are defining this function as a property of the $scope object, so you should use it accordingly:

$scope.getPhoneGapPath()

2 Comments

It is not fair :( You are too fast ))
Ahh, great thanks so much. @nicael You're right he was very fast.

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.