diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..64605a9 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +/screenshots +/example diff --git a/android/.DS_Store b/android/.DS_Store deleted file mode 100644 index 9a874b5..0000000 Binary files a/android/.DS_Store and /dev/null differ diff --git a/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGUIWaveView.java b/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGUIWaveView.java index a1d6ac4..483bd76 100644 --- a/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGUIWaveView.java +++ b/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGUIWaveView.java @@ -21,17 +21,13 @@ public class OGUIWaveView extends View { public OGUIWaveView(Context context) { super(context); - } - - - public void updatePlayHead(float currentSeek){ mCurrentSeek = currentSeek; - invalidate(); } + @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); @@ -49,7 +45,5 @@ protected void onDraw(Canvas canvas) { paint.setStrokeWidth(8); paint.setAntiAlias(true); canvas.drawLine(currrentXPos, 0, currrentXPos, canvas.getHeight(), paint); - } - } diff --git a/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWaveManager.java b/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWaveManager.java index 94ab539..6d142c1 100644 --- a/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWaveManager.java +++ b/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWaveManager.java @@ -3,7 +3,6 @@ import android.support.annotation.Nullable; import android.util.Log; - import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.LifecycleEventListener; @@ -17,7 +16,6 @@ import com.facebook.react.uimanager.annotations.ReactProp; import com.ringdroid.WaveformView; - import static com.facebook.react.common.ReactConstants.TAG; /** @@ -26,9 +24,6 @@ public class OGWaveManager extends SimpleViewManager implements LifecycleEventListener,WaveformView.WaveformListener { - - - private Callback onPressCallback; public static final String REACT_CLASS = "OGWave"; private ReactContext mcontext; @@ -36,12 +31,9 @@ public class OGWaveManager extends SimpleViewManager implements Life @Override public String getName() { - return REACT_CLASS; } - - @Override public OGWaveView createViewInstance(ThemedReactContext context) { context.addLifecycleEventListener(this); @@ -49,10 +41,8 @@ public OGWaveView createViewInstance(ThemedReactContext context) { // deleteFiles(Environment.getExternalStorageDirectory().toString(),"mp3"); OGWaveView mWaveView = new OGWaveView(context); - mWaveView.setWaveformListener(this); - return mWaveView; } @@ -64,7 +54,6 @@ public void setTestId(OGWaveView view, String testId) { @ReactMethod public void testCallback(Callback cb) { - Log.e("XSXGOT","TESXT CA:LBACK CALLED!!! "); String sampleText = "Java is fun"; int textLength = sampleText.length(); @@ -84,47 +73,39 @@ public void setSrc(OGWaveView view, @Nullable ReadableMap src) { public void setComponentID(OGWaveView view, String componentID) { Log.e("XSXGOT","componentID SETTED:::!!!!" +componentID); view.setComponentID(componentID); - } - - @ReactProp(name = "autoPlay", defaultBoolean = false) public void setAutoPlay(OGWaveView view, boolean autoPlay) { Log.e("XSXSXS","setAutoPlay:::: "+autoPlay); view.setAutoPlay(autoPlay); } - @ReactProp(name = "waveFormStyle") public void setWaveFormStyle(OGWaveView view, @Nullable ReadableMap waveFormStyle) { - - view.setmWaveColor(waveFormStyle.getInt("ogWaveColor")); view.setScrubColor(waveFormStyle.getInt("ogScrubColor")); } @ReactProp(name = "play") public void setPlay(OGWaveView view, @Nullable boolean play) { - - view.onPlay(play); - + view.onPlay(play); } - + @ReactProp(name = "stop") + public void setStop(OGWaveView view, @Nullable boolean stop){ + view.onStop(stop); + } /** @ReactProp(name = "pause") public void setPause(OGWaveView view, @Nullable Callback pause){ // view.onPlay(); - } @ReactProp(name = "stop") public void setStop(OGWaveView view, @Nullable Callback stop){ //view.onPlay(); - }**/ - @Override public void onHostResume() { @@ -148,22 +129,18 @@ private void sendEvent(ReactContext reactContext, @Override public void waveformTouchStart(ReactContext context, String componentID) { - WritableMap map = Arguments.createMap(); map.putString("componentID",componentID); sendEvent(context, "OGOnPress",map); Log.e("OGTAGDEBUG::", "waveformTouchStart: " ); - } @Override public void waveformFinishPlay(ReactContext context, String componentID) { - WritableMap map = Arguments.createMap(); map.putString("componentID",componentID); sendEvent(context, "OGFinishPlay",map); Log.e("OGTAGDEBUG::", "waveformFinishPlay: " ); - } @Override @@ -201,4 +178,3 @@ public void waveformZoomOut() { } } - diff --git a/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWavePackage.java b/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWavePackage.java index 4e6b63c..83825e9 100644 --- a/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWavePackage.java +++ b/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWavePackage.java @@ -19,9 +19,6 @@ public class OGWavePackage implements ReactPackage { @Override public List createNativeModules(ReactApplicationContext reactContext) { List modules = new ArrayList<>(); - - - return modules; } diff --git a/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWaveView.java b/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWaveView.java index 9a8d846..10fcd1a 100644 --- a/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWaveView.java +++ b/android/src/main/java/com/otomogroove/OGReactNativeWaveform/OGWaveView.java @@ -23,7 +23,6 @@ public class OGWaveView extends FrameLayout { - private final OGUIWaveView mUIWave; private MediaPlayer mMediaPlayer; private WaveformView mWaveView; @@ -37,9 +36,6 @@ public class OGWaveView extends FrameLayout { private boolean mAutoplay = false; private boolean isCreated = false; - - - public OGWaveView(ReactContext context) { super(context); mContext = context; @@ -47,17 +43,13 @@ public OGWaveView(ReactContext context) { mWaveView = new WaveformView(mContext, this); mUIWave = new OGUIWaveView(mContext); - mUIWave.setBackgroundColor(Color.TRANSPARENT); - - } - public void setmWaveColor(int mWaveColor) { + public void setmWaveColor(int mWaveColor) { this.mWaveView.setmWaveColor(mWaveColor); - - } + public void setScrubColor(int scrubcolor){ mScrubColor = scrubcolor; mUIWave.scrubColor=this.mScrubColor; @@ -65,24 +57,24 @@ public void setScrubColor(int scrubcolor){ } public void onPlay(boolean play){ - if(play){ + if (play) { this.mMediaPlayer.start(); - - - }else{ - if(mMediaPlayer != null && mMediaPlayer.isPlaying()) + } else { + if (mMediaPlayer != null && mMediaPlayer.isPlaying()) mMediaPlayer.pause(); - } progressReportinghandler.postDelayed(progressRunnable, 500); - } + public void onPause(){ this.mMediaPlayer.pause(); } - public void onStop(){ - this.mMediaPlayer.stop(); + + public void onStop(boolean stop) { + if (stop) { + this.mMediaPlayer.stop(); + } } public void setAutoPlay(boolean autoplay){ @@ -94,7 +86,6 @@ public void setAutoPlay(boolean autoplay){ } progressReportinghandler.postDelayed(progressRunnable, 500); - } public void createMediaPlayer() { @@ -104,7 +95,6 @@ public void createMediaPlayer() { addView(this.mUIWave); this.mWaveView.setOnTouchListener(new OnTouchListener(){ - @Override public boolean onTouch(View v, MotionEvent event) { @@ -115,17 +105,13 @@ public boolean onTouch(View v, MotionEvent event) { return true; } - }); - this.mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { - @Override public void onCompletion(MediaPlayer mp) { waveformListener.waveformFinishPlay(mContext, componentID); } - }); } @@ -162,8 +148,6 @@ public void setSoundFile(SoundFile soundFile) { private WaveformView.WaveformListener waveformListener; - - public WaveformView.WaveformListener getWaveformListener() { return waveformListener; } @@ -174,12 +158,10 @@ public void setWaveformListener(WaveformView.WaveformListener waveformListener) private Handler progressReportinghandler = new Handler(); private Runnable progressRunnable = new Runnable() { - public void run() { try { if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { new UpdateProgressRequest().execute(); - // seconds progressReportinghandler.postDelayed(progressRunnable, 100); } @@ -197,18 +179,13 @@ public void setComponentID(String componentID) { this.componentID = componentID; } - protected class UpdateProgressRequest extends AsyncTask { - @Override protected Float doInBackground(Void... params) { - if (mMediaPlayer.isPlaying()) { String offset = Integer.valueOf( mMediaPlayer.getCurrentPosition()).toString(); - - Float currrentPos = (float) mMediaPlayer.getCurrentPosition()/mMediaPlayer.getDuration(); return currrentPos; @@ -219,12 +196,7 @@ protected Float doInBackground(Void... params) { @Override protected void onPostExecute(Float aFloat) { super.onPostExecute(aFloat); - - mUIWave.updatePlayHead(aFloat); } } - - - } diff --git a/android/src/main/java/com/ringdroid/WaveformView.java b/android/src/main/java/com/ringdroid/WaveformView.java index 6c70ba4..63d6e58 100755 --- a/android/src/main/java/com/ringdroid/WaveformView.java +++ b/android/src/main/java/com/ringdroid/WaveformView.java @@ -64,7 +64,6 @@ public void setmURI(String mURI) { public void setmWaveColor(int mWaveColor) { this.mWaveColor = mWaveColor; - mUnselectedLinePaint.setColor(this.mWaveColor); } @@ -73,16 +72,12 @@ public void setmWaveColor(int mWaveColor) { * */ class DownloadFileFromURL extends AsyncTask { - - - /** * Before starting background thread Show Progress Bar Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); - } /** @@ -103,10 +98,7 @@ protected SoundFile doInBackground(String... f_url) { int lenghtOfFile = conection.getContentLength(); // download the file - InputStream input = new BufferedInputStream(url.openStream(), - 8192); - - + InputStream input = new BufferedInputStream(url.openStream(), 8192); // Output stream OutputStream output = new FileOutputStream(filePath); @@ -160,11 +152,8 @@ protected SoundFile doInBackground(String... f_url) { * */ protected void onProgressUpdate(String... progress) { // setting progress percentage - } - - /** * After completing background task Dismiss the progress dialog * **/ @@ -178,13 +167,10 @@ protected void onPostExecute(SoundFile soundFile) { }else{ Log.e("XSXGOT","soundfile is null"); } - } - } - - private String random() { + private String random() { return new BigInteger(130, new SecureRandom()).toString(32); } @@ -273,10 +259,6 @@ public WaveformView(Context context, OGWaveView waveView) { mTimecodePaint.setColor(Color.BLUE); mTimecodePaint.setShadowLayer(2, 1, 1, Color.GRAY); - - - - mSoundFile = null; mLenByZoomLevel = null; mValuesByZoomLevel = null; @@ -289,8 +271,6 @@ public WaveformView(Context context, OGWaveView waveView) { mInitialized = false; } - - public boolean hasSoundFile() { return mSoundFile != null; } @@ -309,8 +289,6 @@ public boolean isInitialized() { return mInitialized; } - - public void setZoomLevel(int zoomLevel) { while (mZoomLevel > zoomLevel) { zoomIn(); @@ -432,16 +410,12 @@ protected void drawWaveformLine(Canvas canvas, protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (mSoundFile == null) return; if (mHeightsAtThisZoomLevel == null) computeIntsForThisZoomLevel(); - - - // Draw waveform int measuredWidth = getMeasuredWidth(); int measuredHeight = getMeasuredHeight(); @@ -453,14 +427,10 @@ protected void onDraw(Canvas canvas) { if (width > measuredWidth) width = measuredWidth; - int i = 0; // Draw waveform - - for (i = 0; i < measuredWidth; i++) { - int stretchedwidthPos = Math.round((i*width)/measuredWidth); Paint paint; @@ -471,19 +441,13 @@ protected void onDraw(Canvas canvas) { ctr - mHeightsAtThisZoomLevel[start + stretchedwidthPos], ctr + 1 + mHeightsAtThisZoomLevel[start + stretchedwidthPos], paint); - - } - - } /** * Called once when a new sound file is added */ private void computeDoublesForAllZoomLevels() { - - Log.e("XSXGOT","computeDoublesForAllZoomLevels"); int numFrames = mSoundFile.getNumFrames(); int[] frameGains = mSoundFile.getFrameGains(); diff --git a/index.js b/index.js index a86b7c8..f4ef69e 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ /** * Created by juanjimenez on 07/12/2016. * Otomogroove ltd 2017 + * Updated by Akio Takei @ 21/06/2019 */ "use strict"; diff --git a/ios/OGWaveManager.m b/ios/OGWaveManager.m index 16e3e06..3ad3564 100644 --- a/ios/OGWaveManager.m +++ b/ios/OGWaveManager.m @@ -10,7 +10,6 @@ #import "OGWaverformView.h" #import - @implementation OGWaveManager RCT_EXPORT_VIEW_PROPERTY(waveFormStyle, NSDictionary); @@ -25,7 +24,6 @@ @implementation OGWaveManager - (UIView *)view { - OGWaverformView *OGWaveformView = [[OGWaverformView alloc] initWithBridge:self.bridge]; [OGWaveformView setDelegate:self]; return OGWaveformView; diff --git a/ios/OGWaveUtils.m b/ios/OGWaveUtils.m index 6671209..42300cd 100644 --- a/ios/OGWaveUtils.m +++ b/ios/OGWaveUtils.m @@ -13,13 +13,13 @@ @implementation OGWaveUtils static NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; +(NSString *) randomStringWithLength: (int) len { - + NSMutableString *randomString = [NSMutableString stringWithCapacity: len]; - + for (int i=0; imSampleRate; channelCount = fmtDesc->mChannelsPerFrame; - // NSLog(@"channels:%u, bytes/packet: %u, sampleRate %f",fmtDesc->mChannelsPerFrame, fmtDesc->mBytesPerPacket,fmtDesc->mSampleRate); } } @@ -341,13 +330,9 @@ - (NSData *) renderPNGAudioPictogramLogForAssett:(AVURLAsset *)songAsset { size_t length = CMBlockBufferGetDataLength(blockBufferRef); totalBytes += length; - - - NSMutableData * data = [NSMutableData dataWithLength:length]; CMBlockBufferCopyDataBytes(blockBufferRef, 0, length, data.mutableBytes); - SInt16 * samples = (SInt16 *) data.mutableBytes; int sampleCount = length / bytesPerSample; for (int i = 0; i < sampleCount ; i ++) { @@ -358,8 +343,6 @@ - (NSData *) renderPNGAudioPictogramLogForAssett:(AVURLAsset *)songAsset { totalLeft += left; - - Float32 right; if (channelCount==2) { right = (Float32) *samples++; @@ -384,7 +367,6 @@ - (NSData *) renderPNGAudioPictogramLogForAssett:(AVURLAsset *)songAsset { if (channelCount==2) { right = totalRight / sampleTally; - if (right > normalizeMax) { normalizeMax = right; } @@ -395,14 +377,10 @@ - (NSData *) renderPNGAudioPictogramLogForAssett:(AVURLAsset *)songAsset { totalLeft = 0; totalRight = 0; sampleTally = 0; - } } - - CMSampleBufferInvalidate(sampleBufferRef); - CFRelease(sampleBufferRef); } } @@ -433,37 +411,18 @@ - (NSData *) renderPNGAudioPictogramLogForAssett:(AVURLAsset *)songAsset { return finalData; } - - - (instancetype)initWithBridge:(RCTBridge *)bridge { if ((self = [super init])) { _bridge = bridge; _isFrameReady = NO; - - } return self; } - - - #pragma mark OGWaveDelegateProtocol -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ - [_delegate OGWaveOnTouch:self componentID:_componentID]; } - - - -/* -// Only override drawRect: if you perform custom drawing. -// An empty implementation adversely affects performance during animation. -- (void)drawRect:(CGRect)rect { - // Drawing code -} -*/ - @end diff --git a/react-native-audiowaveform.podspec b/react-native-audiowaveform.podspec new file mode 100644 index 0000000..a12e719 --- /dev/null +++ b/react-native-audiowaveform.podspec @@ -0,0 +1,17 @@ +require 'json' +package_json = JSON.parse(File.read('package.json')) + +Pod::Spec.new do |s| + + s.name = "react-native-audiowaveform" + s.version = package_json["version"] + s.summary = package_json["description"] + s.homepage = "https://github.com/juananime/react-native-audiowaveform" + s.license = package_json["license"] + s.author = { package_json["author"] => package_json["author"] } + s.platform = :ios, "9.0" + s.source = { :git => package_json["repository"]["url"] } + s.source_files = 'ios/*.{h,m}' + + s.dependency 'React' +end