// App.js
import React, { useState } from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
import { Audio } from 'expo-av';
const App = () => {
const [sound, setSound] = useState();
const [isPlaying, setIsPlaying] = useState(false);
const playSound = async () => {
const { sound } = await Audio.Sound.createAsync(
require('./assets/sample.mp3')
);
setSound(sound);
await sound.playAsync();
setIsPlaying(true);
};
const stopSound = async () => {
if (sound) {
await sound.stopAsync();
setIsPlaying(false);
}
};
return (
<View style={styles.container}>
<Text style={styles.header}>Simple Music Player</Text>
<Button
title={isPlaying ? "Stop" : "Play"}
onPress={isPlaying ? stopSound : playSound}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
header: {
fontSize: 24,
marginBottom: 20,
},
});
export default App;const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
header: {
fontSize: 24,
marginBottom: 20,
},
});
export default App;const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
header: {
fontSize: 24,
marginBottom: 20,
},
});
export default App;const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
header: {
fontSize: 24,
marginBottom: 20,
},
});
export default App;const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
header: {
fontSize: 24,
marginBottom: 20,
},
});
export default App;const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
header: {
fontSize: 24,
marginBottom: 20,
},
});
export default App;