Skip to content

Commit

Permalink
fix audioSession
Browse files Browse the repository at this point in the history
  • Loading branch information
pax-k committed Apr 18, 2024
1 parent 01e3d22 commit 8545385
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StyleSheet, Text, View } from "react-native";
import { ExpoAudioStream } from "expo-audio-stream";
import { ExpoAudioStream } from "@mykin-ai/expo-audio-stream";
import { useEffect } from "react";
import { sampleA } from "./samples/sample-a";
import { sampleB } from "./samples/sample-b";
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ SPEC CHECKSUMS:
EXConstants: 988aa430ca0f76b43cd46b66e7fae3287f9cc2fc
EXFont: f20669cb266ef48b004f1eb1f2b20db96cd1df9f
Expo: e01a77c6fa4bc80a6d1bb949cda1d12d21044abd
ExpoAudioStream: 3072cd8bdca4f0b951cc92f0610ef711724cbe5a
ExpoAudioStream: 43fea6cfb926879caf0c6e90abc99ee855ae52bd
ExpoFileSystem: eecaf6796aed0f4dd20042dc2ca2cac6c4bc1185
ExpoKeepAwake: 0f5cad99603a3268e50af9a6eb8b76d0d9ac956c
ExpoModulesCore: 61dc57c6e2a35f2f84baf488146db624e03af4cd
Expand Down
16 changes: 8 additions & 8 deletions example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');
const path = require('path');
const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");

const config = getDefaultConfig(__dirname);

Expand All @@ -9,20 +9,20 @@ const config = getDefaultConfig(__dirname);
// excludes the one from the parent folder when bundling.
config.resolver.blockList = [
...Array.from(config.resolver.blockList ?? []),
new RegExp(path.resolve('..', 'node_modules', 'react')),
new RegExp(path.resolve('..', 'node_modules', 'react-native')),
new RegExp(path.resolve("..", "node_modules", "react")),
new RegExp(path.resolve("..", "node_modules", "react-native")),
];

config.resolver.nodeModulesPaths = [
path.resolve(__dirname, './node_modules'),
path.resolve(__dirname, '../node_modules'),
path.resolve(__dirname, "./node_modules"),
path.resolve(__dirname, "../node_modules"),
];

config.resolver.extraNodeModules = {
'expo-audio-stream': '..',
"@mykin-ai/expo-audio-stream": "..",
};

config.watchFolders = [path.resolve(__dirname, '..')];
config.watchFolders = [path.resolve(__dirname, "..")];

config.transformer.getTransformOptions = async () => ({
transform: {
Expand Down
4 changes: 2 additions & 2 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"strict": true,
"allowJs": true,
"paths": {
"expo-audio-stream": [
"@mykin-ai/expo-audio-stream": [
"../src/index"
],
"expo-audio-stream/*": [
"@mykin-ai/expo-audio-stream/*": [
"../src/*"
]
}
Expand Down
10 changes: 5 additions & 5 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const createConfigAsync = require('@expo/webpack-config');
const path = require('path');
const createConfigAsync = require("@expo/webpack-config");
const path = require("path");

module.exports = async (env, argv) => {
const config = await createConfigAsync(
{
...env,
babel: {
dangerouslyAddModulePathsToTranspile: ['expo-audio-stream'],
dangerouslyAddModulePathsToTranspile: ["@mykin-ai/expo-audio-stream"],
},
},
argv
);
config.resolve.modules = [
path.resolve(__dirname, './node_modules'),
path.resolve(__dirname, '../node_modules'),
path.resolve(__dirname, "./node_modules"),
path.resolve(__dirname, "../node_modules"),
];

return config;
Expand Down
6 changes: 2 additions & 4 deletions ios/ExpoAudioStreamModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ public class ExpoAudioStreamModule: Module {
private let audioFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 16000.0, channels: 1, interleaved: false)
private var audioEngine = AVAudioEngine()
private var playerNode = AVAudioPlayerNode()
private var audioSessionCategory: AVAudioSession.Category = .playback
private var audioSessionMode: AVAudioSession.Mode = .default

// Two buffer queues for alternating playback, storing tuples of buffers and promises
private var bufferQueueA: [(buffer: AVAudioPCMBuffer, promise: RCTPromiseResolveBlock)] = []
Expand All @@ -31,8 +29,8 @@ public class ExpoAudioStreamModule: Module {
private func configureAudioSession() {
do {
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(self.audioSessionCategory, mode: self.audioSessionMode, options: [])
try audioSession.setActive(true)
try audioSession.setCategory(.playback, mode: .default, options: [.defaultToSpeaker, .allowBluetooth])
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
} catch {
print("Error configuring audio session: \(error)")
}
Expand Down

0 comments on commit 8545385

Please sign in to comment.