1

I'm writing a media player for my android application using angularjs, I get the songs from web API, address: http://10.96.254.34:8885/api/apimusic/download?songId=X, with "X" is the id of the song I want to stream. You can try add "1", "2" or "3" at "X" to listen to the song.
My problem is, when I use write the code for the audio player:

<div class="item item-thumbnail-left">
          <h2>{{song.SongName}}</h2>
          <p>{{song.Singer}}</p>

       <audio id="audio" autoplay="true" preload="auto" tabindex="0" controls="" type="audio/mpeg">
          <source type="audio/mpeg" src="http://10.96.254.34:8885/api/apimusic/download?songId=1">
          Sorry, your browser does not support HTML5 audio.
       </audio>
          </div>

The song can be fetched flawlessly, but when I change it to: http://10.96.254.34:8885/api/apimusic/download?songId={{song.SongId}}, It doesn't work

Any ideas to help me out of this? Please help :(

1
  • use ng-src instead of src Commented Jul 30, 2015 at 12:08

2 Answers 2

2

Try to use in source:

data-ng-src

or

ng-src

instead of using a simple src.

Sign up to request clarification or add additional context in comments.

Comments

2

Its because of Strict Contextual Escaping (SCE), which is by default enabled in Angularjs.

passing expression to url inside href or src is not allowed, so instead prepare your url with expression and then assign it to src. for ex:

Instead of

ng-src="http://yourdomain.com/a={{id}}"

do

in Controller:
    $scope.url = "http://yourdomain.com/a="+$scope.id;
in View
    ng-src="{{url}}"

And make sure of CORS issue as well. If you are calling audio url from different domain.

1 Comment

what error you are getting, please check in console and post it

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.