Skip to content

Commit 5d70364

Browse files
committed
Update README.md
1 parent 2f75cca commit 5d70364

File tree

1 file changed

+2
-147
lines changed

1 file changed

+2
-147
lines changed

README.md

Lines changed: 2 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,2 @@
1-
# React NowPlaying
2-
3-
> Don’t Be the Grinch! Or Cross-Browser Compatibility Problems — Mike Mackrory
4-
5-
![NPM Version](https://img.shields.io/npm/v/react-nowplaying)
6-
[![Discord](https://dcbadge.vercel.app/api/server/xWRaCDBtW4?style=flat)](https://discord.gg/xWRaCDBtW4)
7-
8-
A cross-browser cross-device friendly React context to auto-play audio in a browser.
9-
10-
## Demo
11-
12-
See it in action here: [https://react-nowplaying.vercel.app](https://react-nowplaying.vercel.app/?utm_source=readme.md)
13-
14-
## Getting Started
15-
16-
### Installation
17-
18-
```bash
19-
npm i react-nowplaying
20-
```
21-
22-
### Add to your project
23-
24-
Import the React context provider;
25-
26-
```tsx
27-
import { NowPlayingContextProvider } from "react-nowplaying";
28-
```
29-
30-
And, just as any custom context provider, wrap the part of your app you need to be context aware in the custom provider's tags.
31-
32-
```tsx
33-
// layout.tsx
34-
35-
//...
36-
37-
export default function RootLayout({
38-
children,
39-
}: Readonly<{
40-
children: React.ReactNode;
41-
}>) {
42-
return (
43-
<html lang="en">
44-
<body className={inter.className}>
45-
<NowPlayingContextProvider>{children}</NowPlayingContextProvider> // e.g. custom provider tags wrap entire body of app
46-
</body>
47-
</html>
48-
);
49-
}
50-
```
51-
52-
### Play Blob data
53-
54-
Now, you can provide your data `Blob` to the play function.
55-
56-
```tsx
57-
export default function MyComponent() {
58-
const { play } = useNowPlaying();
59-
60-
const playAudio = () => {
61-
// get your audio blob
62-
play(blob, "audio/mp3");
63-
};
64-
65-
return (
66-
<button type="button" onClick={() => playAudio()}>
67-
Play Audio
68-
</button>
69-
);
70-
}
71-
```
72-
73-
### Play a URL string
74-
75-
Now, you can provide your url `string` to the play function.
76-
77-
```tsx
78-
export default function MyComponent() {
79-
const { play } = useNowPlaying();
80-
81-
const playAudio = () => {
82-
// get your audio blob
83-
play("https://your-file.com/audio.mp3", "audio/mp3");
84-
};
85-
86-
return (
87-
<button type="button" onClick={() => playAudio()}>
88-
Play Audio
89-
</button>
90-
);
91-
}
92-
```
93-
94-
## Audio Controls
95-
96-
Using our context's hook, we return native controls from the `<audio>` native, with the exception of `play()`. If you `pause()` your audio, you can now use `resume()`.
97-
98-
The `player` property is also available from the hook, which is a native reference to our `<audio>` tag, giving you the ability to add your own event listeners and control it as you need to.
99-
100-
```ts
101-
export default function MyComponent() {
102-
const { pause, resume } = useNowPlaying();
103-
104-
//... build your controls
105-
}
106-
```
107-
108-
## How It Works
109-
110-
In our recent project, we faced challenges with automatically playing audio across different browsers and devices, including Safari, Firefox, and all iOS devices. Our solution involved complex adjustments to enable automatic playback of audio files (in Blob format) received from our API. Instead of utilizing the Web Audio API, we opted for a workaround that involves a hidden audio element on the webpage. Here’s how it works:
111-
112-
- When audio is ready to play, the webpage updates a hidden audio element with the audio source and type, allowing the audio to play automatically.
113-
- We created a custom hook that exposes an instance of the audio element, making it easier to manage playback. The hook extends the interface of an audio element.
114-
115-
This approach allows for seamless audio playback across a wide range of browsers and devices, ensuring users have a consistent experience.
116-
117-
## Getting Help
118-
119-
We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:
120-
121-
- [Open an issue in this repository](https://github.com/deepgram-devs/react-nowplaying/issues)
122-
- [Join the Deepgram Github Discussions Community](https://github.com/orgs/deepgram/discussions)
123-
- [Join the Deepgram Discord Community](https://discord.gg/xWRaCDBtW4)
124-
125-
## Author
126-
127-
[Deepgram](https://deepgram.com)
128-
129-
## Known Issues
130-
131-
For a list of known issues and potential bugs, please visit our [Issues](https://github.com/deepgram-devs/react-nowplaying/issues) page. We regularly update this section as new issues are discovered and resolved.
132-
133-
## Collaborating
134-
135-
We welcome contributions from the community. For instructions on how to get involved, please read our [Collaborating Guide](CONTRIBUTING.md).
136-
137-
## Code of Conduct
138-
139-
To ensure a welcoming and safe environment for all contributors, we adhere to a Code of Conduct. All participants in our project are expected to read and follow our [Code of Conduct](CODE_OF_CONDUCT.md). We are committed to making participation in this project a harassment-free experience for everyone.
140-
141-
## Changelog
142-
143-
Stay updated with the changes and improvements made to our project by checking out our [Changelog](CHANGELOG.md). This document includes a detailed list of changes, including new features, bug fixes, and other important updates.
144-
145-
## License
146-
147-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
1+
# Free AI at api.airforce
2+
https://discord.gg/AJDsM7jtbq

0 commit comments

Comments
 (0)