I am currently working on an app that has to play audio from an external source. It is in the .amr file format, but giving it the URL and looking at log cat I can see its trying to access it locally logging:
FAILED renaming /storage/sdcard0/tmprecording.3gp to /storage/sdcard0/http://URL/audio.amr
Here is my player code
function play(source) {
var media = new Media(source, Played, Failed);
media.play();
document.getElementById('status').innerHTML = "playing";
}
with the function linked to a button and given a URL to the audio. I am testing this out on Android.
Thanks!
Never mind, it was just an issue with formats, .amr is an incompatible format so it didnt work
Related
I am having an app build with Cordova and Angular JS. I am trying to play a sound when a new event occurs and I am trying to achieve this by creating an append of tag within the new event function and then calling #mySound.play(). When I test it on my desktop browser there it is working perfectly on every new event I can hear the sound playing but on the other hand when I create it's APK through Phonegap and test it on my Samsung Galaxy there it isn't playing any sound on new event. Kindly let me know if I am missing anything or what could be a better way to achieve this goal?
function displayEvents(data,div_id)
{
var icon_trans_type=''; var icons=''; var icons2='';
var htm='';
$.each( data, function( key, val ) {
var new_tag='';
if (val.viewed==1){
$('<audio id="chatAudio"><source src="locales/android/raw/notify.mp3" type="audio/mp3"></audio>').appendTo('body');
$('#chatAudio')[0].play();
new_tag='<div class="new-tag rounded" id="new-event">'+ getTrans('new','new') +'</div>';
}
});
//createElement('new-events',htm);
createElement(div_id,htm);
}
The play method provided by HTML5 API is useful for playing media files available on the web. Cordova provides the media plugin to play local media files in device.
Cordova Media Plugin should do the trick for you as it is supported in various mobile platforms like Android, iOS, Windows, BlackBerry etc.
As mentioned in this line:
private static final String CATALOG_URL =
"http://storage.googleapis.com/automotive-media/music.json";
This file contains a list of tracks that are hosted by Google online.
So, I guess the complete URL of Jazz_In_Paris.mp3 would be
https://www.youtube.com/audiolibrary/music/Jazz_In_Paris.mp3
but getting 404 Not Found in a same way I have tried
https://www.youtube.com/audiolibrary/music/album_art.jpg
but again same result 404 Not Found
So here are my few small questions:
1. What is the complete URL of `Jazz_In_Paris.mp3` and `album_art.jpg`
2. Where they have used site object "site" : "https://www.youtube.com/audiolibrary/music" in application (in which class and where)
3. Where I have to make changes in my code, If I would like to get JSON from my own Server "http://www.domain.com/services/music.json"
4. How can I create my own Youtube Audio Library, Like in my Library I would like to add my favourite youtube songs
What is the complete URL of Jazz_In_Paris.mp3 and album_art.jpg
http://storage.googleapis.com/automotive-media/album_art.jpg
http://storage.googleapis.com/automotive-media/The_Messenger.mp3
Where they have used site object "site" : "https://www.youtube.com/audiolibrary/music" in application (in which class and where)
this url not used any where in app.
Where I have to make changes in my code, If I would like to get JSON from my own Server "http://www.domain.com/services/music.json"
yes, you can use same json for your app but just change path to your server(just create same json format)
How can I create my own Youtube Audio Library, Like in my Library I would like to add my favourite youtube songs
Universal Music Player: use Google storage client to store music files but you can also create own you tube channel and make private video. use it in your app
EDITED:
"site" json object is useless. this object is json because of previous version of app they have used that. currently not.
youtube channel and Google storage both are different thing. Google storage mainly used to store files which we are able to use in our app.
in you tube every one can upload video which is private/public(if you are going to use that in your app then use private). for more detail check you support articals
i suggest you to use Google Storage API or you can also upload files on your own server!
I'm working on a simple app that has but a few functions, that is supposed to play audio ether from a web site ie.
function playfile(){
var playing = "http://static.weareswoop.com/audio/charlestown/track_1.mp3";
var my_media = new Media(playing,
function() {
alert("playAudio():Audio Success");
},
function(err) {
if(err.message != undefined) { alert("playAudio():Audio Error: "+err.message); }
if(err.code != undefined) { alert("playAudio():Audio Error: "+err.code); }
});
// Play audio
my_media.play();
}
with the html of
play
No matter what I do this does not work on Andriod (version 2.X and 4.X), but does work just fine on iOS (v5 iPad 1 tested).
If I do this against a web based file, I get no response from either the Success or Failure functions, but if I run this agains a local file on the SD car i.e. file:///mnt/sd-card/mining/charlestown/track1.mp3 I get error code 1 without an error message.
Any help would be more than welcomed.
edit: to get the local file version which I am using FileTransfer() download (which works just fine on any OS).
window.appRootDirName = "mining"; // sets the working directory
var playing = window.appRootDir.fullPath + "/track1.mp3"; // sets filename
Thus I end up with a URI file:///mnt/sd-card/mining/track1.mp3 which is the exact correct uri when working on 2.x Samsung Galaxy Y.
Again, I must stress, this entire situation works on iOS, but not on Android. On Android when getting a HTTP: based file it gives no error or success, on FILE:// it gives error code 1 when trying to play.
You have to add in the android_asset/www/ to the filepath in order to get it to play from the file see the following bug.
Playing local sound in phonegap
this should solve the playing a local file part of the problem
I tried playing http://static.weareswoop.com/audio/charlestown/track_1.mp3 and it plays fine for me using Cordova 3.0 and android 4.3
Playing media files does not work when running via the PhoneGap Desktop / PhoneGap Developer apps. It does work when you do a "real" build, for example using PhoneGap Build, and then install the app on your phone.
So as well as using the full file path, as described in other answers, you also need to be running a "real" build.
It looks like this is a bug that PhoneGap know about and have on their list: https://github.com/phonegap/phonegap-app-desktop/issues/335.
The following code is a snippet of a much larger project I'm working on. The problem is when I test the app in Flash CS6 urlLoader reads 25Notes.txt perfectly but when I try debugging the app (via Flash's built in "Debug>Debug Movie>On Device via USB") on my Android device (HTC Incredible) urlLoader throws a stream error #2032.
I'm deploying the app with Captive Runtime from AIR 3.2 using Flash CS6 and my project is organized with no extraneous files or folders.
Please let me know if you have any insight or suggestions and if you need more of an explanation or code.
I'm also not sure if Captive Runtime in Flash CS6 packages all of the local files in the root project folder or just the ones used in the app or none at all. Any information about this would be greatly appreciated as well.
var FILE_LIST_PATH:String = "/25Notes/25Notes.txt";
var mp3List:Array = new Array();
LoadFile();
function LoadFile()
{
var urlRequest:URLRequest = new URLRequest(FILE_LIST_PATH);
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, processTextFile);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
urlLoader.load(urlRequest);
}
function onIOError(e:IOErrorEvent){
trace("can't load file list: " + e);
}
function processTextFile(event:Event):void
{
var loader:URLLoader = URLLoader(event.target);
var textFile:String = loader.data;
mp3List = textFile.split("\n");
for (i=0;i<mp3List.length;i++){
trace(mp3List[i],i);
}
}
Here's what the IOError trace returns:
can't load file list: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: app:/25Notes/25Notes.txt" errorID=2032]
I'm totally stumped. Please help!!
Is the file being saved by the app at runtime and you are trying to retrieve it? If not, that URL is incorrect. The app:/ directory is the applicationStorageDirectory on the device, not a location within the app itself. You'll need to embed your txt file as a Class and access it that way
[Embed(source="assets/ui/images/phone/menu-myvideos-active-160.png")]
var MyVideosActive160:Class;
That is something from a project I am actually working on finishing right now. That embeds an image and allows me to access it afterward. To access it, I simply do
var bmp:Bitmap = new MyVideosActive160();
If you don't embed, I don't believe you can actually access the file. Every file that needs to be included within the app must be embedded.
If you are saving the file at run time at some point, you'll want to do it this way
var path:String = new File(new File.applicationStorageDirectory.resolvePath("/25Notes/25Notes.txt").nativePath).url;
That will output a file:/// URL, rather than a url using app:/. I am using this method to play downloaded videos in my app. It's a crappy workaround that Adobe should have built into SDK, but that's what we have to deal with.
I am using MediaPlayer to play my video from a URL that I have parsed from a Youtube json-c feed. The feed I retrieved is:
"player":
{"default":"https://www.youtube.com/watch?v=4uwtqRBE4Kk&feature=youtube_gdata_player",
"mobile":"https://m.youtube.com/details?v=4uwtqRBE4Kk"},
"content":
{"5":"https://www.youtube.com/v/4uwtqRBE4Kk?version=3&f=videos&app=youtube_gdata",
"1":"rtsp://v3.cache1.c.youtube.com/CiILENy73wIaGQmp4EQQqS3s4hMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
"6":"rtsp://v3.cache2.c.youtube.com/CiILENy73wIaGQmp4EQQqS3s4hMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"},"
I am using
//URL I retrieved from a json-c feed from the player array described above
private String URL = "https://m.youtube.com/watch?v=4uwtqRBE4Kk";
mediaplayer.setDataSource(URL);
It gives a MediaPlayerError error(1, -2147483648). Whereas when I use the URL from a dropbox like
private String URL = "http://dl.dropbox.com/u/145894/t/rabbits.3gp";
It runs and the video is played. Please explain the error or give me a remedy.
If you are testing on devices earlier than Android 3.1 you might not be able to play AACP.
In order to find out what streams you can play on your targeted device check official docs: http://developer.android.com/reference/android/media/AudioManager.html
If you are looking how to handle aacp checkout following:
https://stackoverflow.com/a/8833346/200272