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 :(
Try to use in source:
data-ng-src
or
ng-src
instead of using a simple src.
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.
Related
I'm having an issue making the Volume to 0 when the deviceready is triggered. Currently my codes are
<div id="dvVideo">
<video webkit-playsinline playsinline id="videoPlayback" poster="#">
<source src="#" type="video/mp4">
</video>
</div>
and scripts are
var vidcont = document.getElementById('dvVideo');
document.addEventListener('deviceready', function() {
vidcont.style.display = "none";
vid.src = "http://linktovideo.com/test.mp4";
vid.load();
vid.play();
vid.volume = 0.0;
});
What am I trying to achieve is that the video should preload before a button is clicked to play the video and it has to be hidden. What I'm currently doing is playing the video in the background, while the it is displayed as none, then when the button is pressed, it will displayed as block and video.currentTime is set to 0.0. Which makes the video seems to load fast.
Is there any alternative way to do this? I'm thinking of the preload="metadata" etc. but can't seem to get it to work. Can someone explain on the preload thing?
Edit: It works fine on any browsers but I just can't make it work on Android.
Currently I'm working on news reader android app, and show article in webview, I have some issues when displaying embedded video from youtube, my WYSIWYG generate code below
<iframe height="360" width="640" src="//www.youtube.com/embed/PS6JupCFnNM" frameborder="0" allowfullscreen></iframe>
but it cannot load in webview, then I found something to fixed this problem, with adding http/https in src url like
<iframe width="560" height="315" src="https://www.youtube.com/embed/PS6JupCFnNM" frameborder="0" allowfullscreen></iframe>
the second format is original from youtube embed box that I copied from there, and it work, now what I supposed to do, is there a way to make webview show the youtube video with src="//www.youtube.com/embed/PS6JupCFnNM" format or I must modification my WYSIWYG instead?
thanks for your help. I hope my question does not duplicate with another webview question.
You have to use base url.
webView.loadDataWithBaseURL("http://.", htmlCode, TEXT_HTML, "UTF-8", "");
Switch to loadDataWithBaseURL(), where the base URL that you provide has the https scheme.
i was done by adding utf-8 encoding.
like that:
webview.loadData(html,"text/html", "utf-8");
need some help.
I'm building an app with HTML5 and using 'Intel XDK' to convert it to an .apk for android. The only issue I'm having is 'Looping' audio files.
I'm using a pretty simple code:
<audio id="myAudio" autoplay loop>
<source src="sounds/mysound.mp3" type="audio/mpeg"/>
<source src="sounds/mysound.ogg" type="audio/ogg"/>
</audio>
When I test the app the sound plays, but only once, no loop.
Thanks in advance!
You can achieve this in Java script in HTML by:
<script language="JavaScript" type="text/javascript">
var mp3snd = "songlocation.mp3";
var oggsnd = "home-sound.ogg";
document.write('<audio loop autoplay="autoplay">');
document.write('<source src="'+mp3snd+'" type="audio/mpeg">');
document.write('<source src="'+oggsnd+'" type="audio/ogg">');
document.write('<!--[if lt IE 9]>');
document.write('<bgsound src="'+mp3snd+'" loop="1">');
document.write('<![endif]-->');
document.write('</audio>');
//-->
</script>
It will achieve the same effect that you want (playing in background) while still being in HTML 5.
Installing this plugin might also help.
(Update for issue with XDK Android Sound Loop)
So I've made a compromise that works! Loops when app is running,but it won't run when the phone is locked.. Tested using Intel XDK Android build.
I created an internal IFRAME, that refreshes itself when the sound is over. Example below is a 1 minute sound:
On the page that audio is required:
<div id="audio_stream" style="position: absolute; margin-left: -1000px;">
<iframe src="iframes/audiotrack.html"></iframe>
</div>
This is the IFRAME code: (location: iframes/audiotrack.html)
<!--First, include refresh in meta-->
<meta http-equiv="refresh" content="60;url=audiotrack.html" />
<!--now enter audio that you wish to loop-->
<div id="audio_stream">
<audio controls autoplay="autoplay">
<source src="../sounds/FX/audiotrack.mp3" type="audio/mpeg"/>
</audio>
</div>
So it works, but not in the background. Anyone have any idea on how to keep this playing when the phone is locked?
I have been at this for days and have had no luck with trying to trouble shoot. So I have multiple live streams up on my site and I wanted to put this in an app but everytime I upload to phonegap and download on my phone the video wont play.
Neither the Flash or HTML5 version of the app plays. I simply copied the code I used on the site to place in my index.html document of my app but for some reason it fails. The message I get reads something like (going off memory) Either there was a problem with the network or server or this file is not supported). Although I know that isnt the fact because it works when I view the site from my phone, just not the app.
Markup looks something like this:
<head>
<script type="text/javascript" src="http://www.my-domain.com/jwplayer/jwplayer.js"></script>
</head>
<body>
div id='mediaplayer2'>
<script type="text/javascript"> jwplayer('mediaplayer2').setup({
'id': 'playerID', 'width': '388', 'height': '218',
'provider': 'rtmp',
'streamer': 'rtmp://0.0.0.0/some-directory',
'autostart': 'true',
'stretching': 'exactfit',
levels: [{
bitrate: "800",
file: "my-file-name",
width: "1280"
}],
'modes': [
{type: 'flash', src: 'http://www.my-domain.com/jwplayer/player.swf'},
{
type: 'html5',
config: {
levels: [ {'file': 'http://0.0.0.0/some-directory/playlist.m3u8'} ],
'provider': 'video'
}
}
]
});
</script>
<video
id="mediaplayer2"
controls="1"
autoplay="1"
height="218"
preload="none"
src="http://0.0.0.0/some-directory/playlist.m3u8"
width="388">
</video>
</div>
</body>
What do I need to do different to get this to work in an app like it does in my browser? Im developing in Dreamweaver and even when I hit "Live" it streams perfectly, just not in app.
Thanks in advance
Use Vitamio Player it can play all kind of streaming also its open source,. u just need to include this as library into ur project and make sure to use vitamio videoview or mediaplayer,. k no worry take a look at this Sample to include Vitamio into ur project
Hope its Helps you,.
Regards
Rajeev
Anyone know for sure if playing local mp3 file using HTML5 is possible or not in Android?
Playing mp3 files from url's works fine, but not when embedded in the app. Been searching for definitive answer.
Thanks for any help
<html>
<head>
<title>Audio Player</title>
</head>
<body>
<br /> <br />
<audio id="player" autoplay loop controls="controls">
<source src="bassscales.mp3" />
</audio>
<br /> <br />
<div>
<button style="width:85;height:75" button onclick="document.getElementById('player').play()">Play</button>
<button style="width:85;height:75" button onclick="document.getElementById('player').pause()">Pause</button>
<button style="width:85;height:75" button onclick="document.getElementById('player').pause(); document.getElementById('player').currentTime = 0;">Stop</button>
</div>
</body>
</html>
I had the same problem with HTML5 and <video> tag, video playing fine if called programatically from file system, but when called from the tag, didn't work,
the way I solved it is having a javascript function in the HTML call the android system, in your case for playing an mp3
Android JavaScriptInterface tutorial
also check my question in the same subject
note that you need to place in the correct folder the mp3 [sorry don't remember in which folder, make a search and find it easy]
so first do a hello world javascript calling a log or basic function in android,
then make the javascript call the play function,
good luck
ps.
playing mp3 from assets folder example
and calling Android methods with javascript
jsInterface example
Does this look correct for the HTML file?
<body>
<video id="video" controls height="270" src="http://dl.dropbox.com/u/39276137/intro1girl.mp4" width="480">
</video>
<script type="text/javascript">
var video = document.getElementById('video');
video.addEventListener('click',function(){
MyAndroid.video.play();
},false);
</script>
then don't know what to put in the JavaScriptInterface.java class...thanks for all the help :)