React-native-sound: [Android + iOS] Build errors incompatible types: Double cannot be converted to Integer, etc.

Created on 20 Feb 2018  路  19Comments  路  Source: zmxv/react-native-sound

  • Building and using react-native-sound was working fine on RN 0.53.0, and then it was not.
  • A brand new project with RN 0.53.3 builds fine.

Sorry I am stumped. Any suggestions are appreciated.

  • I have tried unlink and link.
  • Manually removing all traces of 'sound' from build files, react-native link react-native-sound
  • Comparing a new working project build settings to my existing project.

my-app/source/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/ RNSoundModule.java:43: error: cannot find symbol final ReactContext reactContext = this.context; ^ symbol: class ReactContext location: class RNSoundModule my-app/source/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/ RNSoundModule.java:207: error: incompatible types: Double cannot be converted to Integer setOnPlay(false, key); ^ my-app/source/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/ RNSoundModule.java:223: error: incompatible types: Double cannot be converted to Integer this.focusedPlayerKey = key; ^
my-app/source/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/
RNSoundModule.java:260: error: incompatible types: Double cannot be converted to Integer
setOnPlay(true, key);
^
my-app/source/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/
RNSoundModule.java:284: error: incomparable types: Double and Integer
if (!this.mixWithOthers && key == this.focusedPlayerKey) {
^
my-app/source/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/
RNSoundModule.java:416: error: incompatible types: Integer cannot be converted to Double
this.pause(this.focusedPlayerKey, null);
````

app/build.gradle
````
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

updateVersionInfoJs()

android {
dexOptions {
    javaMaxHeapSize "4g"
}

defaultConfig {
    applicationId "com.ditchwitch.fieldscout"
    minSdkVersion 16
    multiDexEnabled true
    targetSdkVersion 22
    versionCode getBuildNumber()
    versionName getVersionString()
    setProperty("archivesBaseName", "field-scout-android-$versionName")        
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
}

````

"react": "^16.2.0", "react-native": "^0.53.3", "react-native-sound": "^0.10.4",

iOS Build Errors:
my-app/source/node_modules/react-native-sound/RNSound/RNSound.h:11:1: error: missing '@end' @interface RNSound : NSObject <RCTBridgeModule, AVAudioPlayerDelegate> ^ my-app/source/node_modules/react-native-sound/RNSound/RNSound.h:10:1: note: class started here @interface RNSound : RCTEventEmitter <RCTBridgeModule, AVAudioPlayerDelegate> ^ my-app/source/node_modules/react-native-sound/RNSound/RNSound.h:11:20: error: expected identifier or '(' @interface RNSound : NSObject <RCTBridgeModule, AVAudioPlayerDelegate> ^ my-app/source/node_modules/react-native-sound/RNSound/RNSound.m:14:13: error: property implementation must have its declaration in interface 'RNSound' or one of its extensions @synthesize _key = _key; ^ my-app/source/node_modules/react-native-sound/RNSound/RNSound.m:20:53: error: property '_key' not found on object of type 'RNSound *' AVAudioPlayer* player = [self playerForKey:self._key]; ^ my-app/source/node_modules/react-native-sound/RNSound/RNSound.m:221:8: error: property '_key' not found on object of type 'RNSound *' self._key = key;
Thank you for sharing your work and react-native-sound !

Thanks in advance for any tips or suggestions.

bug duplicate

Most helpful comment

@trepidity just tried 0.10.7 . iOS is okay, android still throws errors

RNSoundModule.java:207: error: incompatible types: Double cannot be converted to Integer setOnPlay(false, key);
RNSoundModule.java:223: error: incompatible types: Double cannot be converted to Integer this.focusedPlayerKey = key;
RNSoundModule.java:232: error: incompatible types: Double cannot be converted to Integer setOnPlay(false, key);
RNSoundModule.java:248: error: incompatible types: Double cannot be converted to Integer setOnPlay(false, key);
RNSoundModule.java:260: error: incompatible types: Double cannot be converted to Integer setOnPlay(true, key);
RNSoundModule.java:284: error: incomparable types: Double and Integer if (!this.mixWithOthers && key == this.focusedPlayerKey) {
RNSoundModule.java:308: error: incomparable types: Double and Integer if (!this.mixWithOthers && key == this.focusedPlayerKey) {
RNSoundModule.java:416: error: incompatible types: Integer cannot be converted to Double this.pause(this.focusedPlayerKey, null);
RNSoundModule.java:420: error: incompatible types: Integer cannot be converted to Double this.play(this.focusedPlayerKey, null);

RN version 0.53.3

All 19 comments

This sounds like the same issue:

cannot compile android with RN 0.53 #379

Neither rolling back to RN 0.52.2 nor installing react-native-sound from master resolved this strange issue.

"react-native-sound": "https://github.com/zmxv/react-native-sound.git",

I am stumped.

What could have messed up both Android and iOS builds on an existing project that even rolling back to 0.52.2 cannot fix?

It seems like something is affecting both the Android and iOS build tools.

I'm guessing it's related to this change... #375
Would you agree?

@trepidity Thanks. These #375 errors seem to be related to what I have been seeing.

I see they were committed directly to the master branch.

Does that mean that npm install or yarn will grab these changes as soon as changes are committed to the master?

And the package.json version number remains unchanged at 0.10.4?

Yikes! I did not know that could happen. Who knows how many of my dependencies may have similar changes with package versions unchanging.

I am not a node expert. How can I detect or control unknown changes from happening?

Hum, we are on 0.10.6 now. yarn install uses yarn.lock, so it wont upgrade unless you choose yarn upgrade. https://github.com/yarnpkg/yarn/issues/1978

Yarn install looks at the npmjs release, not master.

What do you mean, looks like 0.10.4 on master to me. I'm having the same issues.

https://github.com/zmxv/react-native-sound/blob/master/package.json

@trepidity I did remember doing a ncu within the past several days and seeing a new react-native-sound update available. It could have been 0.10.6. I do not recall.

So I did a:
yarn add react-native-sound
But @aforty is seeing 0.10.4 on the master package.json as well.

{ "name": "react-native-sound", "version": "0.10.4",

oops. sheepish grin. Try now :(

@trepidity Same compile errors after yarn add to version 0.10.6
````
"react-native-sound": "^0.10.6",

: error: cannot find symbol
final ReactContext reactContext = this.context;

7: error: incompatible types: Double cannot be converted to Integer
setOnPlay(false, key);
````

I still do not understand why creating a new project from scratch, adding react-native-sound, and adding an import to react-native-sound to App.js file, then call a Sound.method() or two, and yet is has no compile errors?

How does yarn add react-native-sound know to get latest package from the web or it's cache?

Does yarn use package version numbers?

Or does it use a hash or something?

I discovered I did not have yarn.lock added to git. It is now. Perhaps this is a clue in the sequence of unfortunate events?

Lockfiles should be committed on all projects

This lockfile contains information about the exact versions of every single dependency that was installed as well as checksums of the code to make sure the code is identical.

A few weeks ago, this 0.10.4 yarn.lock was working fine:
react-native-sound@^0.10.4:: version "0.10.4" resolved "https://registry.yarnpkg.com/react-native-sound/-/react-native-sound-0.10.4.tgz#242286558f457e023dbed42e8c6cbe52cfd313d4"

Likely, a bug was introduced with one of the recent commits.

Work-around:

"react-native-sound": "v0.10.2",

Any new about the fix?

There is a chance that it will be in the next 24hrs.

please, thanks

for all who are having this problem, go to
node_modules\react-native-sound\android\srcmain\java\com\zmxv\RNSound\RNSoundModule.java
and replace all the file contents with following code-

package com.zmxv.RNSound;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.net.Uri;
import android.media.AudioManager;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.ExceptionsManagerModule;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.io.IOException;
import android.util.Log;
public class RNSoundModule extends ReactContextBaseJavaModule {
Map playerPool = new HashMap<>();
ReactApplicationContext context;
final static Object NULL = null;
public RNSoundModule(ReactApplicationContext context) {
super(context);
this.context = context;
}
@Override
public String getName() {
return "RNSound";
}
@ReactMethod
public void prepare(final String fileName, final Integer key, final ReadableMap options, final Callback callback) {
MediaPlayer player = createMediaPlayer(fileName);
if (player == null) {
WritableMap e = Arguments.createMap();
e.putInt("code", -1);
e.putString("message", "resource not found");
return;
}
final RNSoundModule module = this;
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
boolean callbackWasCalled = false;
@Override
public synchronized void onPrepared(MediaPlayer mp) {
if (callbackWasCalled) return;
callbackWasCalled = true;
module.playerPool.put(key, mp);
WritableMap props = Arguments.createMap();
props.putDouble("duration", mp.getDuration() * .001);
try {
callback.invoke(NULL, props);
} catch(RuntimeException runtimeException) {
// The callback was already invoked
Log.e("RNSoundModule", "Exception", runtimeException);
}
}
});
player.setOnErrorListener(new OnErrorListener() {
boolean callbackWasCalled = false;
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
if (callbackWasCalled) return true;
callbackWasCalled = true;
try {
WritableMap props = Arguments.createMap();
props.putInt("what", what);
props.putInt("extra", extra);
callback.invoke(props, NULL);
} catch(RuntimeException runtimeException) {
// The callback was already invoked
Log.e("RNSoundModule", "Exception", runtimeException);
}
return true;
}
});
try {
player.prepareAsync();
} catch (IllegalStateException ignored) {
// When loading files from a file, we useMediaPlayer.create, which actually
// prepares the audio for us already. So we catch and ignore this error
}
}
protected MediaPlayer createMediaPlayer(final String fileName) {
int res = this.context.getResources().getIdentifier(fileName, "raw", this.context.getPackageName());
if (res != 0) {
return MediaPlayer.create(this.context, res);
}
if(fileName.startsWith("http://") || fileName.startsWith("https://")) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Log.i("RNSoundModule", fileName);
try {
mediaPlayer.setDataSource(fileName);
} catch(IOException e) {
Log.e("RNSoundModule", "Exception", e);
return null;
}
return mediaPlayer;
}
File file = new File(fileName);
if (file.exists()) {
Uri uri = Uri.fromFile(file);
// Mediaplayer is already prepared here.
return MediaPlayer.create(this.context, uri);
}
return null;
}
@ReactMethod
public void play(final Integer key, final Callback callback) {
MediaPlayer player = this.playerPool.get(key);
if (player == null) {
callback.invoke(false);
return;
}
if (player.isPlaying()) {
return;
}
player.setOnCompletionListener(new OnCompletionListener() {
boolean callbackWasCalled = false;
@Override
public synchronized void onCompletion(MediaPlayer mp) {
if (!mp.isLooping()) {
if (callbackWasCalled) return;
callbackWasCalled = true;
try {
callback.invoke(true);
} catch (Exception e) {
//Catches the exception: java.lang.RuntimeException路Illegal callback invocation from native module
}
}
}
});
player.setOnErrorListener(new OnErrorListener() {
boolean callbackWasCalled = false;
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
if (callbackWasCalled) return true;
callbackWasCalled = true;
callback.invoke(false);
return true;
}
});
player.start();
}
@ReactMethod
public void pause(final Integer key, final Callback callback) {
MediaPlayer player = this.playerPool.get(key);
if (player != null && player.isPlaying()) {
player.pause();
}
callback.invoke();
}
@ReactMethod
public void stop(final Integer key, final Callback callback) {
MediaPlayer player = this.playerPool.get(key);
if (player != null && player.isPlaying()) {
player.pause();
player.seekTo(0);
}
callback.invoke();
}
@ReactMethod
public void release(final Integer key) {
MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.release();
this.playerPool.remove(key);
}
}
@ReactMethod
public void setVolume(final Integer key, final Float left, final Float right) {
MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.setVolume(left, right);
}
}
@ReactMethod
public void setLooping(final Integer key, final Boolean looping) {
MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.setLooping(looping);
}
}
@ReactMethod
public void setSpeed(final Integer key, final Float speed) {
MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.setPlaybackParams(player.getPlaybackParams().setSpeed(speed));
}
}
@ReactMethod
public void setCurrentTime(final Integer key, final Float sec) {
MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.seekTo((int)Math.round(sec * 1000));
}
}
@ReactMethod
public void getCurrentTime(final Integer key, final Callback callback) {
MediaPlayer player = this.playerPool.get(key);
if (player == null) {
callback.invoke(-1, false);
return;
}
callback.invoke(player.getCurrentPosition() * .001, player.isPlaying());
}
//turn speaker on
@ReactMethod
public void setSpeakerphoneOn(final Integer key, final Boolean speaker) {
MediaPlayer player = this.playerPool.get(key);
if (player != null) {
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
AudioManager audioManager = (AudioManager)this.context.getSystemService(this.context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(speaker);
}
}
@ReactMethod
public void enable(final Boolean enabled) {
// no op
}
@Override
public Map getConstants() {
final Map constants = new HashMap<>();
constants.put("IsAndroid", true);
return constants;
}
}

Master and unstable have been updated. version 0.10.7 has been published. This should no longer be an issue.

@trepidity just tried 0.10.7 . iOS is okay, android still throws errors

RNSoundModule.java:207: error: incompatible types: Double cannot be converted to Integer setOnPlay(false, key);
RNSoundModule.java:223: error: incompatible types: Double cannot be converted to Integer this.focusedPlayerKey = key;
RNSoundModule.java:232: error: incompatible types: Double cannot be converted to Integer setOnPlay(false, key);
RNSoundModule.java:248: error: incompatible types: Double cannot be converted to Integer setOnPlay(false, key);
RNSoundModule.java:260: error: incompatible types: Double cannot be converted to Integer setOnPlay(true, key);
RNSoundModule.java:284: error: incomparable types: Double and Integer if (!this.mixWithOthers && key == this.focusedPlayerKey) {
RNSoundModule.java:308: error: incomparable types: Double and Integer if (!this.mixWithOthers && key == this.focusedPlayerKey) {
RNSoundModule.java:416: error: incompatible types: Integer cannot be converted to Double this.pause(this.focusedPlayerKey, null);
RNSoundModule.java:420: error: incompatible types: Integer cannot be converted to Double this.play(this.focusedPlayerKey, null);

RN version 0.53.3

Android throws errors, indeed.

Still happening here

RN: 0.51.0
RNSound: 0.10.7

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leenasn picture leenasn  路  5Comments

pawelsas picture pawelsas  路  4Comments

kurokky picture kurokky  路  3Comments

therealproblem picture therealproblem  路  5Comments

VladimirJarabica picture VladimirJarabica  路  3Comments