Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
cuong0993 committed Mar 1, 2021
1 parent 9fac207 commit 910d19f
Show file tree
Hide file tree
Showing 105 changed files with 1,932 additions and 1,878 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- master

env:
flutter_version: "1.22.5"
flutter_version: "1.22.6"

jobs:
buildApk:
Expand Down
8 changes: 8 additions & 0 deletions .run/AndroidDev.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="AndroidDev" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--flavor=dev" />
<option name="buildFlavor" value="dev" />
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method v="2" />
</configuration>
</component>
9 changes: 0 additions & 9 deletions .run/Dev.run.xml

This file was deleted.

6 changes: 6 additions & 0 deletions .run/IosDev.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="IosDev" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method v="2" />
</configuration>
</component>
7 changes: 7 additions & 0 deletions .run/instrument_checker.dart.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="instrument_checker.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" nameIsGenerated="true">
<option name="filePath" value="$PROJECT_DIR$/lib/instrument_checker.dart" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import io.flutter.plugin.common.MethodChannel
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.chaomao.hitnotes/sound_player").setMethodCallHandler(SoundPlayerPlugin())
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.chaomao.hitnotes/sound_player").setMethodCallHandler(SoundMethodCallHandler())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.chaomao.hitnotes

import android.media.AudioAttributes
import android.media.AudioManager
import android.media.SoundPool
import android.os.Build
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import kotlin.math.pow

class SoundMethodCallHandler : MethodChannel.MethodCallHandler {
private lateinit var soundPool: SoundPool
private var loadedCount = 0
private var soundIds = mapOf<Int, Int>()
private var rates = mapOf<Int, Float>()
private var activeSounds = arrayListOf<Int>()
private val maxStreams = 8

override fun onMethodCall(methodCall: MethodCall, result: MethodChannel.Result) {
when (methodCall.method) {
"load" -> {
val arguments = methodCall.arguments as Map<String, Any>
val soundPaths = arguments["soundPaths"] as Map<Int, String>
val baseNotes = arguments["baseNotes"] as Map<Int, Int>
soundPool = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
SoundPool.Builder()
.setMaxStreams(maxStreams)
.setAudioAttributes(AudioAttributes.Builder().setLegacyStreamType
(AudioManager.STREAM_MUSIC)
.setUsage(AudioAttributes.USAGE_GAME)
.build())
.build()
} else {
SoundPool(maxStreams, AudioManager.STREAM_MUSIC, 1)
}.apply {
setOnLoadCompleteListener { _, _, _ ->
loadedCount++
if (loadedCount == soundPaths.size) {
result.success(null)
}
}
}
val ids = hashMapOf<Int, Int>()
for ((baseNote, path) in soundPaths) {
val soundId = soundPool.load(path, 1)
ids[baseNote] = soundId
}
rates = baseNotes.mapValues { 2f.pow((it.key - it.value).toFloat() / 12f) }
this.soundIds = baseNotes.mapValues { ids[it.value]!! }
}
"play" -> {
val arguments = methodCall.arguments as Map<String, Any>
val note = arguments["note"] as Int
val streamId = soundPool.play(soundIds[note]!!, 1.0f, 1.0f, 0,
0, rates[note]!!)
activeSounds.add(streamId)
if (activeSounds.size > maxStreams) {
val firstSound = activeSounds.first()
soundPool.stop(firstSound)
activeSounds.remove(firstSound)
}
result.success(null)
}
"release" -> {
if (this::soundPool.isInitialized) {
soundPool.release()
}
loadedCount = 0
activeSounds.clear()
result.success(null)
}
else -> {
result.notImplemented()
}
}
}
}

This file was deleted.

Loading

0 comments on commit 910d19f

Please sign in to comment.