Play sound from assets folder on iphone simulator Phonegap - ios

Im trying to play a sound which is located in my asset folder; www/cssScript/sound/Chicken.mp3. Im using the media object from phonegap to do so, and it works fine on Android, and I know its no problem with the media object itself. Im trying to play it in my simulator, but are not able to do so, and have no iPhone currently available.
Is it possible to play audio located locally with the iphone simulator? If so, what do I do wrong? This is the path I give to my media object:
/Users/thomastveten/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/5F9867C8-1919-4238-87F9-EED4EA893155/GuessThisSound.app/www/cssScript/sound/Chicken.mp3
I get the path by using the code below:
var path = window.location.pathname;
// path = path.substr( 0, path.length - 10 );
// return path;
var phoneGapPath = path.substring(0, path.lastIndexOf('/') + 1);

Related

Actionscript netStream play mp4 with ios

I'm trying to play a video from an app using Flash Builder 4.7, AIRSDK 31.0 and ios 12.
private function init():void{
holder.addChild(video);
this.addElement(holder);
nc.connect(null);
ns = new NetStream(nc);
ns.client = {};
ns.client.onMetaData = ns_onMetaData;
ns.client.onCuePoint = ns_onCuePoint;
video.attachNetStream(ns);
ns.play("Videos/video.mp4");
ns.addEventListener(NetStatusEvent.NET_STATUS, statusNet);
}
This works on simulators and on android devices, but not for ios devices. I've seen a couple of similiar questions but they are trying to stream an mp4 from a "http" address where mine is using a local file.
I've been asked to stick to mp4 format, although I have read using an FLV file should work.
Special considerations for H.264 video in AIR 3.0 for iOS
For H.264 video, the iOS APIs for video playback accept only a URL to a file or stream. You cannot pass in a buffer of H264 video data to be decoded.
So do I need to find a new way of playing the video other than netStream or am I best to swap to a different file type?
As a side note Adobe says to write your mp4 URLs like this:
("mp4:samples/myvideo.mp4");
My app can't find the file with "mp4:" at the front of the URL.
If you are wanting to play videos that are packaged with your iOS app it's important to ensure you are actually including them when you compile your app.
Untested but something like this should work.
var _dFile:File;
var _ns:NetStream;
var _nc:NetConnection;
var _customClient:Object;
var _video:Video;
_customClient = new Object();
_customClient.onMetaData = metaDataHandler;
_nc = new NetConnection();
_nc.connect(null);
_ns = new NetStream(_nc);
_ns.client = _customClient;
//this is the important bit for finding files within the .ipa bundle.
_dFile = File.applicationStorageDirectory.resolvePath("nameOfYourVideoDirectory/nameOfVideo.mp4");
_ns.play(_dFile.url);
_video = new Video(480, 340);
_video.attachNetStream(_ns);
_ns.addEventListener(NetStatusEvent.NET_STATUS, onNSComplete, false, 0, true);
private function metaDataHandler(infoObject:Object):void {
trace("Length of video",infoObject.duration);
}
private function onNSComplete(e:NetStatusEvent):void{
if(e.info.code == "NetStream.Buffer.Empty") {
//do something
}
}
However, I would highly recommend using an ANE to play video on mobile via the native media player. Take a look at Distriqt MediaPlayer ANE.

No sound on BlackBerry with openfl

I try to use haxe (openfl) for blackberry development.
And I test PlayingSound sample - it works.
But when I try to load sound from url - doesn't work.
Here is my code:
public function PlaySong(url:String):Void{
var _url:URLRequest = new URLRequest(url);
if (_soundChannel != null) _soundChannel.stop();
_song = new Sound();
_song.load(_url); //<--Do not work
//_song = Assets.getSound("assets/stars.mp3"); <--work
_soundChannel =_song.play(0);
}
In the flash target this code is playing my sound from the url, but when I deploy app to my device - it have no sound. On the device, sound is playing correctly only if I load it from the asset folder.
Also, I see that soundChannel position is always 0 (on device);
I try firstly to load the sound with loader, and then play it, when the loading is complete, but it's not help me too.
Help me, please.
PS Sorry for my English.
Have you tried loading it using this:
var loader:URLLoader = URLLoader(new URLRequest("url"));
loader.data = DataFormat.BINARY;
then try
loader.addEventListener(Event.COMPLETE, onComplete);
function onComplete(e:Event):Void
{
sound.loadCompressedDataFromByteArray(e.data.content)
}
Try to load bytes first, then create sound from that.
Anyway, if your code works on other mobile devices(maybe emulators), then create new issue here:
https://github.com/openfl/openfl

MonoTouch: Problems downloading and playing video from external URL

I can play a video from the local file system, but can't get it to play from an external URL. No error message. Just a blank dark screen. Any ideas?
var movieFile = NSUrl.FromString("http://apps.focusonsound.com/demo/AppleVideos/Xylophone.mp4");
mp = new MPMoviePlayerController(movieFile);
mp.AllowsAirPlay = false;
this.View.AddSubview(mp.View);
mp.SetFullscreen(true, true);
mp.ShouldAutoplay = true;
mp.PrepareToPlay();
mp.Play();
Your code works - but only when I replace your URL with one where a .mp4 file can be downloaded (e.g. using Safari).
Could your URL simply be dead / outdated ?

PhoneGap Media API cannot overwrite recorded audio on iPhone device

I have an audio file 'default.wav' in 'www/audio/' folder. In iOS simulator, I can record audio, overwrite the 'www/audio/default.wav', and play it. However, on the real device, the 'default.wav' cannot be overwritten. The device always play the unchanged audio file no matter how many times I record.
Could anyone please tell me how to save the new recorde audio or overwrite to 'default.wav' in 'www/audio/' folder on the device? I am using phonegap 1.3.0 on iPhone running iOS5.
function recordAudio() {
var src = "audio/default.wav";
mediaRec = new Media(src, onSuccess, onError);
mediaRec.startRecord();
}
function stopRecordAudio(){
mediaRec.stopRecord();
mediaRec.release();
alert('stopRecordAudio');
}
function playAudio() {
var src = "audio/default.wav";
mediaPlay = new Media(src, onSuccessPlay, onErrorPlay);
mediaPlay.play();
}
You can't overwrite files in the www directory. These are part of your application.

Save encoded .mp3 to applicationStorageDirectory Adobe Air iOS

I'm developing an iOS iPad app w/ Flash CS5.5 AIR v.3.1
I'm using ShineMp3Encoder to encode a Wav to a Mp3 from:
https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy
Basically it converts a byteArray (wav) to a byteArray (mp3) or "mp3encoder.mp3Data" in the code.
I have no trouble saving this using a (new FileReference()).save(mp3Data, filename); but because this is being used in a iOS AIR app I wanted to switch to using the File.applicationStorageDirectory so that I could put the saved mp3 into it's own folder to keep organized. When I run the code it goes through all the steps, converts the wav to mp3, and then says that it saves but doesn't with no errors. The sound IS stored in memory, as it is able to be played back until the app is closed. I've changed the resolvePath to the root folder, myApp/, and to /sounds - None of which work. I've never attempted to do this before so I'm a little lost why no file is being created. Anyone with any suggestions would help a lot.
function onEncoded(e:Event):void{
myTI.text = "Mp3 encoded and saved. Press Play.";
mp3encoder.mp3Data.position = 0;
var myDate:Date = new Date();
var theDate:String = myDate.monthUTC.toString() + myDate.dayUTC.toString()
+ myDate.hoursUTC.toString() + myDate.minutesUTC.toString()
+ myDate.secondsUTC.toString();
var file:File = File.applicationStorageDirectory.resolvePath("myApp/sounds/myVoice+"+theDate+".mp3");
var fileStream:FileStream = new FileStream;
fileStream.open(file,FileMode.UPDATE);
fileStream.writeBytes(mp3encoder.mp3Data);
fileStream.close();
}
Untested but try this. If it works, modify the filename to be dynamic as you require.
var myfilename:File = File.applicationStorageDirectory;
myfilename = myfilename.resolvePath("myVoice.mp3");
var outputStream:FileStream = new FileStream();
outputStream.open(myfilename,FileMode.WRITE);
outputStream.writeBytes(mp3encoder.mp3Data,0,mp3encoder.mp3Data.length);
outputStream.close();
I know my answer is little bit late, but maybe it will be useful for somebody who will find this post in future.
When you develop on Windows in Adobe AIR and try to save something in File.applicationStorageDirectory it will NOT saved in the same folder like your swf or fla file.
It will be saved here:
C:\Users[WIN_LOGIN]\AppData\Roaming[APP_ID]\Local Store
Your APP_ID you will find and set in Publish Settings for IOS.

Resources