react-native-sound does not work on ios emulator - react-native

the below code works fine on android and the sound is played....however on ios simulator it does not.
Ive added my sound file to Xcode project, and no error is caught.....when I step through code, it runs this.sound.play() successfully and callback function is called...however you dont hear any sound.
import Sound from 'react-native-sound';
sound = new Sound('sound.mp3');
try {
this.sound.setCategory('Playback');
this.sound.play(() => {
this.sound.stop();
this.sound.release();
});
} catch (e) {
console.log('cannot play the sound file', e);
}

If you have the newest Xcode 11.6, did you try messing around with the settings in
Simulator > I/O > Audio Output
(if it's an older xcode, maybe Simulator > Hardware > Audio Output)?

Where you have put the sound file, please note that the sound clip files should be placed under the directory android/app/src/main/res/raw for android and For iOS, Add your sounds to Resources in Xcode project

Related

React native app can not play mp3 after disconnecting from computer

I save an mp3 file named 'sound1.mp3' in assets folder.
In App.js, I call:
let sound1 = new Sound(requires('./assets/sound1.mp3'), Sound.MAIN_BUNDLE, (error) => {});
sound1.play((ok) => {});
It worked. But when I disconnect my android phone from my computer and restart the app, it can not play mp3 file.
Please help me.
When we disconnect from the development server, It sometimes results in unexpected behavior. Create an APK and try with that.

Open file downloaded within React-Native app with another app

I am trying to open files (images, pdfs, videos, etc) downloaded with my React-Native app from my server.
So I'm using RNFetchBlob to download the file then I'm doing the following depending if it's an iOS or Android device:
openFile = (item, path) => {
if (Platform.OS === 'ios') {
RNFetchBlob.ios.previewDocument(path)
} else {
// I've tried setting a real mimetype instead of / but it still doesn't work
RNFetchBlob.android.actionViewIntent(path, '/')
}
}
On iOS it works as expected but nothing happens on Android even though I have apps that can read images, pdfs or videos on the device I'm testing on.
Any ideas why this doesn't work or how I could make the same thing with another library ?
Found out the reason for this, it's a know bug of the library and has a PR waiting to be merged (no timeframe from the repo owner).
Here is the link to the PR: https://github.com/joltup/rn-fetch-blob/pull/317
So basically this needs to be added to line 122-123 of file android/src/main/java/com/RNFetchBlob/RNFetchBlob.java:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
If above is not working do to the below step:
overwrite the 121 line in android/src/main/java/com/RNFetchBlob/RNFetchBlob.java:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 121 line
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // 122 line

PhoneGap / iOS7 / XCode 5 / Mavericks: compiles but doesn't really work

I have used Phonegap several times but since the upgrade to Mavericks / Xcode5 everything has changed.
If I try to create a helloworld project, everything looks good: it compiles and launches the simulator or installs the app on my phone. The problem is if I try to add any Phonegap functionality, the it just won't work.
UPDATE: this is how I'm creating the project:
cordova create helloworld
cordova platform add ios
I have tried directly opening helloworld.xcodeproj in Xcode, using the "cordova run ios", "cordova prepare", "cordova build" commands but none of them seems to make any difference (some of these create and copy a lot of files, but there is no difference regarding the access to "device" variable)
The only way of debugging I have managed to use is to show alerts and try/catch blocks like this:
try {
alert(device);
// var text = '';
// var i = 0;
// for (var attribute in window) {
// text = text + '\n' + attribute;
// i++;
// }
// alert("total " + i + " keys: " + text);
} catch (err) {
alert(err);
}
Trying to read from "device" variable results in the following:
The text on this error suggests that one should use the following command
phonegap plugin add thePlugin
That indeed works: it adds the desired feature on the config.xml file, but the problem persits, so it does not look like an issue related to permissions. The same thing occurs when installing and trying to use other plugins, such as accelerometer or notifications.
I really liked Phonegap because it made things easier, but now it seems the opposite. One optoin is to use an older version of Phonegap and/or Xcode, but that's not what I'm looking for.
So, what is my configuration?
Mavericks 10.9.1
Xcode 5.0.2 (5A3005)
Phonegap / cordova 3.3.0
iOS 7.0.4 (iPhone 5) --> or the emulator
Any clues?
Thanks
I finally managed to solve this issue.
The solution is simple, yet it was difficult to detect.
Every time you add a plugin using the following command: cordova plugin add thePlugin you then need to run the cordova prepare command again. This is tricky, because if you take a look at the code after adding the plugin there is some setup/changes made. But these changes aren't enough, so cordova prepare might first seem redundant, but solves the issue.
So:
create the project
add as many plugins as you might use
start developing either:
(a) directly on the generated YOURAPP.xcodeproj file, and NEVER run
the cordova prepare commmand again, otherwise you will delete all your
changes
(b) work on the "general" www folder of your project and then run cordova prepare everytime you need to create a new version. Note:
you'll need to close the xcodeproj file in order to see any changes
I tend to think that alternative "(a)" should be the optimal, just make sure you don't overwrite your files or keep your files properly versioned

MediaPlayer Error (1, -2147483648) android programing

I have been having some issues with my code to play html5 vide.
I created a short presentation in powerpoint and exported it html5, it contain a
video, I have copy the exported files into my assets files in android buy my video
is not playing.
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebChromeClient;
import android.webkit.WebViewClient;
public class WebViewActivity7 extends Activity {
private WebView webView7;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview7);
webView7 = (WebView) findViewById(R.id.webView8);
webView7.getSettings().setJavaScriptEnabled(true);
webView7.getSettings().setAllowFileAccess(true);
webView7.getSettings().setPluginsEnabled(true);
webView7.getSettings().setAllowFileAccess(true);
webView7.setWebChromeClient(new WebChromeClient());
webView7.setWebViewClient(new WebViewClient());
webView7.getSettings().setBuiltInZoomControls(true);
webView7.loadUrl(url);
}
String url ="file:///android_asset/HTML5.html";
}
Everything else on my presentation works like a charm except the video, it does not play and i get the following error, when I tabbed on the video to play it on the scree on my android tablet - Android 4.0:
MediaPlayer Error (1, -2147483648)
I have been trying to get a solution to my problem for the last 5 days, I have read quite a few forums, change my code several times and nothing.
I found on a post that the reasons for the above error are:
File path is in error. Incorrect directory or Url or Uri found.
Media file is in error, incompatible format.
Missing permissions.
I have checked all the above on my app and still can't find how to solve it.
Everything else on my html5 file and folder works fine, so i don't think is a directory problem.
My embedded video files are .mp4 and .webm sand there are supposed to be supported.
I look at the permission of my files and folder and all seems to be fine.
I have an iPad version of my app working fine with the same html5 files and folder and the videos work fine.
Anyone have any idea how can I fix this problem, coding is supposed to be fun but after 5 days on this problems i am having second thoughts.
Thank you.
DPP
Addition to above:
I found in another forum that android does not allow to play video files larger than 1MB, Is this true? One of my videos is 3.2 MB and the other one is 29MB.
Answer:
the data about the video size is not true per what I have observed. I have set up my videos (Video files MP4 only with not HTML5 code) to play from the "res/raw" folder and it is all good. I just can't get them to play from the assets folder embedded on HTML5.
Still looking around for solutions, but having my videos on the "res/raw" folder it is a good alternative to my problem.
DPP
I have solved this problem by using copyAssets into sd card and running the index.HTML from the sdcard. see post Running an html5 site withing android app

Getting error while packaging the code for ipad device using flashbuilder

This is vengatesh. I am developing mobile application for android devices and apple ipad, using flashbuilder 4.5 premium.After the completion of code , I can easily create apk file for android devices but I couldn't be able to create ipa file for APPLE devices.While packaging , I got some java exception error like
"Exception in threa "main" java.lang.NullPointerException"
Please guide me on this issue . I am in urgency to complete my project for ipad devices
i used the my indexedarray as
for( var j:int = 0; j<controlsXML.length(); j++)
{
if(sectionXML[i].#Name == controlsXML[j].#SectionName)
{
indexedArray.push({controlName:controlsXML[j].#Name,Horder:controlsXML[j].#HOrder,Vorder:controlsXML[j].#VOrder});
}
}
indexedArray.sortOn(["Horder","Vorder"],[Array.NUMERIC,Array.NUMERIC]);
Try these links will helpful for you:
http://va.lent.in/blog/2011/03/25/air2-6-app-for-ios/
http://www.adobe.com/devnet/air/articles/packaging-air-apps-android.html
http://tv.adobe.com/.../build-your-first-mobile-application-in-flash-builder-45/
http://help.adobe.com/en_US/as3/iphone/WS789ea67d3e73a8b2-48bca492124b39ac5e2-7ffb.html
http://help.adobe.com/en_US/air/build/WSfffb011ac560372f2fea1812938a6e463-8000.html
http://www.riagora.com/2010/12/tips-for-flex-mobile-apps/
http://www.adobe.com/devnet/flex/articles/mobile_development_hero_burrito.html
http://tv.adobe.com/watch/adc-presents/flex-mobile-part-2-navigation-and-lists/
http://www.yeahbutisitflash.com/?p=986
http://www.instructables.com/id/How-to-use-Adobes-iPhone-Packager-without-an-Appl/
Are you following all the steps of packaging correctly?