Comments (7)
Sound.setCategory('Record')
#在录音之前把Sound的类型设置为这个,问题就全解决了
from react-native-recording.
我拉了你的example,发现没问题,于是我就怀疑是跟我某个包有冲突了,经过排查发现是react-native-sound
,只要装了这个包,IOS真机
(其他的都没问题,只有真机)就会出现Sending
recording with no listeners registered.
这个是sound的项目地址https://github.com/zmxv/react-native-sound
这是他的index.js
// Type definitions for react-native-sound
// Project: https://github.com/zmxv/react-native-sound
// Definitions by: Kyle Roach <https://github.com/iRoachie>
// TypeScript Version: 2.3.2
type AVAudioSessionCategory = 'Ambient' | 'SoloAmbient' | 'Playback' | 'Record' | 'PlayAndRecord' | 'AudioProcessing' | 'MultiRoute'
type AVAudioSessionMode = 'Default' | 'VoiceChat' | 'VideoChat' | 'GameChat' | 'VideoRecording' | 'Measurement' | 'MoviePlayback' | 'SpokenAudio'
export default class Sound {
static MAIN_BUNDLE: string
static DOCUMENT: string
static LIBRARY: string
static CACHES: string
/**
* Sets AVAudioSession as active, which is recommended on iOS to achieve seamless background playback.
* Use this method to deactivate the AVAudioSession when playback is finished in order for other apps
* to regain access to the audio stack.
*
* @param category AVAudioSession category
* @param mixWithOthers Can be set to true to force mixing with other audio sessions.
*/
static setActive(active: boolean): void
/**
* Sets AVAudioSession category, which allows playing sound in background,
* stop sound playback when phone is locked, etc.
* Parameter options: "Ambient", "SoloAmbient", "Playback", "Record", "PlayAndRecord", "AudioProcessing", "MultiRoute".
*
* @param category AVAudioSession category
* @param mixWithOthers Can be set to true to force mixing with other audio sessions.
*/
static setCategory(category: AVAudioSessionCategory, mixWithOthers: boolean): void
/**
* Sets AVAudioSession mode, which works in conjunction with the category to determine audio mixing behavior.
* Parameter options: "Default", "VoiceChat", "VideoChat", "GameChat", "VideoRecording", "Measurement", "MoviePlayback", "SpokenAudio".
*
* @param mode AVAudioSession mode
* @param mixWithOthers Can be set to true to force mixing with other audio sessions.
*/
static setMode(mode: AVAudioSessionMode): void
/**
* @param filename Either absolute or relative path to the sound file
* @param basePath Optional base path of the file. Omit this or pass '' if filename is an absolute path. Otherwise, you may use one of the predefined directories: Sound.MAIN_BUNDLE, Sound.DOCUMENT, Sound.LIBRARY, Sound.CACHES.
* @param onError Optional callback function if loading file failed
*/
constructor(filename: string, basePath: string, onError: (error: any) => void)
/**
* Return true if the sound has been loaded.
*/
isLoaded(): boolean
/**
* Plays the loaded file
* @param onEnd - Optional callback function that gets called when the playback finishes successfully or an audio decoding error interrupts it
*/
play(onEnd?: () => void): void
/**
* Pause the sound
* @param cb - Optional callback function that gets called when the sound has been paused.
*/
pause(cb?: () => void): void
/**
* Stop playback and set the seek position to 0.
* @param cb - Optional callback function that gets called when the sound has been stopped.
*/
stop(cb?: () => void): void
/**
* Release the audio player resource associated with the instance.
*/
release(): void
/**
* Return the number of channels
* (1 for mono and 2 for stereo sound), or -1 before the sound gets loaded.
*/
getNumberOfChannels(): number
/**
* Return the volume of the audio player (not the system-wide volume),
* Ranges from 0.0 (silence) through 1.0 (full volume, the default)
*/
getVolume(): number
/**
* Set the volume
* @param value - ranging from 0.0 (silence) through 1.0 (full volume)
*/
setVolume(value: number): void
/**
* Return the stereo pan position of the audio player (not the system-wide pan)
* Ranges from -1.0 (full left) through 1.0 (full right). The default value is 0.0 (center)
*/
getPan(): number
/**
* Set the pan value
* @param value - ranging from -1.0 (full left) through 1.0 (full right).
*/
setPan(value: number): void
/**
* Return the loop count of the audio player.
* The default is 0 which means to play the sound once.
* A positive number specifies the number of times to return to the start and play again.
* A negative number indicates an indefinite loop.
*/
getNumberOfLoops(): number
/**
* Set the loop count
* @param value - 0 means to play the sound once. A positive number specifies the number of times to return to the start and play again (iOS only). A negative number indicates an indefinite loop (iOS and Android).
*/
setNumberOfLoops(value: number): void
/**
* Callback will receive the current playback position in seconds and whether the sound is being played.
* @param cb
*/
getCurrentTime(cb?: (seconds: number, isPlaying: boolean) => void): void
/**
* Seek to a particular playback point in seconds.
* @param value
*/
setCurrentTime(value: number): void
/**
* Speed of the audio playback (iOS Only).
* @param value
*/
setSpeed(value: number): void
/**
* Whether to enable playback in silence mode (iOS only)
* @deprecated - Use the static method Sound.setCategory('Playback') instead which has the same effect.
* @param enabled
*/
enableInSilenceMode(enabled: boolean): void
/**
* Sets AVAudioSession category
* @deprecated
* @param value
*/
setCategory(value: AVAudioSessionCategory): void
/**
* Turn speaker phone on (android only)
* @param value
*/
setSpeakerphoneOn(value: boolean): void
}
oc的代码我不太懂,有没有可能是命名冲突,假如不用sound
我这边也要改不少代码,边录边获取流的包全github大概就你这个能用了,我们这边是小团队,没什么大牛,非常能希望结交想你这样的优秀程序员,看到的话不知道能不能给个微信
from react-native-recording.
Sending `recording` with no listeners registered. 的意思是没有注册相应的监听函数,大概是你的写法有问题,与其他库没什么关系,况且,react-native-sound 并没有任何关于 recording
的使用。
退一步,这也只是一个 warning,release 的时候会被忽略的,不过我确实应该在 send event 之前检查
listener 有没有注册。
from react-native-recording.
@qiuxiang 同样的代码在安卓的真机和模拟器,还有IOS的模拟器上都是好的,唯有IOS的真机在link了react-native-sound
之后会出现获取不到监听数据的情况,至于写法,你的这个组件用起来总共就三行,应该不会出问题的吧
from react-native-recording.
我锁定问题了,是sound的这个方法导致的
Sound.setCategory('Playback');
把这个去掉一切正常,一旦启动这个,你的这个包在IOS真机上就没法用了,不过你的这个init方法一旦启用,他的setCategory
就不需要设置也能播放声音了,所以我暂时的解决方案是,在初始化App的时候直接Recording.init
来代替Sound
的setCategory
,不过还是希望你的下个版本能解决这个问题
from react-native-recording.
应该是 你recording 里面的 setCategory('Playback') 之前先判断下是否已经监听
from react-native-recording.
I wasn't using react-native-sound
but was using a different module (react-native-tone). Adding this code to the module fixed the issue:
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:&setCategoryError];
from react-native-recording.
Related Issues (20)
- iOS录音结束后播放音频声音很小 HOT 3
- Recorder cannot record more than 1 time if audio is played after recording (iOS) HOT 2
- QUESTION: How to create a file? HOT 1
- How to dump the audio samples to file to play with Audacity
- EXC_BAD_ACCESS code=257 on refresh
- Undefined is not an object (evaluating Recording.init) HOT 1
- warn The following packages use deprecated "rnpm" config that will stop working from next release:
- Not working on 0.62 HOT 5
- How to find real-time audio level HOT 1
- TypeError: null is not an object (evaluating "Recording.init") HOT 5
- EventListener not working once stop is called. HOT 1
- One more listener runs and its callback returns always zeros HOT 1
- TypeError: null is not an object (evaluating 'Recording.init') HOT 3
- How to reduce the size to 5.17 KiB/s?
- Native module cannot be null in IOS HOT 5
- does it show the wave animation while recording?? HOT 1
- How to save recording result to a file or server ?
- Callback not firing on iOS HOT 2
- How to enable listening in background?
- null is not an object (evaluating 'RNAudioRecord.init') HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-recording.