Skip to content

samjt/react-native-ios-network-audio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

react-native-ios-network-audio

IOS class to add react-native implementation for web audio urls(look at AVPlayer documentation for audio compatibility). Tested using mp3 urls.

Add it to your project

  1. Run 'npm install react-native-ios-network-audio --save'
  2. Add .h and .m files to "your_project_name" folder in XCode and restart application
  3. var audio = require('react-native').NativeModules.RNAudioPlayerURL;

Basic usage

//To initialize the audio clip
audio.initWithURL("http://your_audio_url_here");

//To retrieve the length of the clip in seconds as a float
audio.getDuration((duration) => {
	//do what you need with duration variable
	//***Example
	var minutes = Math.floor(duration/60);
	var seconds = Math.ceil((duration/60 - minutes) * 60);
	this.setState({minutes: minutes, seconds: seconds, totalSeconds: duration});
});

//To play audio clip
audio.play();

//To pause audio clip
audio.pause();

New Additions

  1. Audio will automatically set time to zero once it has reached the end
  2. New Function to seek to a certain time in the audio clip
//Listen for audio end
var {NativeAppEventEmmiter} = require('react-native');
var subscription = NativeAppEventEmitter.addListener(
	'AudioEnded',
	(trigger) => {console.log(trigger.event)};
);

//To seek to a specific time in seconds
audio.seekToTime(time_in_seconds);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 100.0%