当前位置: 首页 > 软件库 > 手机/移动开发 > >

react-native-track-player

授权协议 Apache-2.0 License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 蓬长恨
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

A fully-fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!


⚠️ V2 Migration Guide

All queue methods have been updating to work on indexes instead of id's. We want this library to support all kinds of apps -- and moving to be index based will allow us to better support applications who have long/endless queues and in the future to allow us to build a performant API around queue management.

We recommend using Typescript to have the system alert you of issues.

When migrating from v1 to v2, the following has changed:

// Methods

- async function add(tracks: Track | Track[], insertBeforeId?: string): Promise<void> {
+ async function add(tracks: Track | Track[], insertBeforeIndex?: number): Promise<void> {

- async function remove(tracks: string | string[]): Promise<void> {
+ async function remove(tracks: number | number[]): Promise<void> {

- async function skip(trackId: string): Promise<void> {
+ function skip(trackIndex: number): Promise<void> {

- async function updateMetadataForTrack(trackId: string, metadata: TrackMetadataBase): Promise<void> {
+ async function updateMetadataForTrack(trackIndex: number, metadata: TrackMetadataBase): Promise<void> {

- async function getTrack(trackId: string): Promise<Track> {
+ async function getTrack(trackIndex: number): Promise<Track> {

- async function getCurrentTrack(): Promise<string> {
+ async function getCurrentTrack(): Promise<number> {

// Imports

import TrackPlayer, {
-  STATE_XXX,
-  CAPABILITY_XXX,
-  PITCH_ALGORITHM_XXX,
-  RATING_XXX,
+  State,
+  Capability,
+  PitchAlgorithm,
+  RatingType,
+  Event,
+  RepeatMode
} from 'react-native-track-player'

// Hooks

- useTrackPlayerProgress
+ useProgress

// Event Listeners
// Refrain from using: TrackPlayer.addEventListener() and instead use the provided hooks

+ usePlaybackState
+ useTrackPlayerEvents
+ useProgress

Features

  • Lightweight - Optimized to use the least amount of resources according to your needs
  • Feels native - As everything is built together, it follows the same design principles as real music apps do
  • Multi-platform - Supports Android, iOS and Windows
  • Media Controls support - Provides events for controlling the app from a Bluetooth device, the lock screen, a notification, a smartwatch or even a car
  • Local or network, files or streams - It doesn't matter where the media belongs, we've got you covered
  • Adaptive bitrate streaming support - Support for DASH, HLS or SmoothStreaming
  • Caching support - Cache media files to play them again without an internet connection
  • Background support - Keep playing audio even after the app is in background
  • Fully Customizable - Even the notification icons are customizable!
  • Supports React Hooks �� - Includes React Hooks for common use-cases so you don't have to write them

Quick Guides

Why another music module?

After trying to team up modules like react-native-sound, react-native-music-controls and react-native-google-cast, I've noticed, that their structure and the way should be tied together can cause a lot of problems (mainly on Android). Those can heavily affect the app stability and user experience.

All audio modules (like react-native-sound) don't play in a separated service on Android, which should only be used for simple audio tracks in the foreground (such as sound effects, voice messages, etc.)

react-native-music-controls is meant for apps using those audio modules, but it has a few problems: the audio isn't tied directly to the controls. It can be pretty useful for casting (such as Chromecast).

react-native-google-cast works pretty well and also supports custom receivers, but it has fewer player controls, it's harder to integrate and still uses the Cast SDK v2.

First Steps

If you want to get started with this module, check the Getting Started page.

If you want detailed information about the API, check the Documentation. You can also look at our example project here.

Example

A basic example of how to play a track:

import TrackPlayer from 'react-native-track-player';

const start = async () => {
    // Set up the player
    await TrackPlayer.setupPlayer();

    // Add a track to the queue
    await TrackPlayer.add({
        id: 'trackId',
        url: require('track.mp3'),
        title: 'Track Title',
        artist: 'Track Artist',
        artwork: require('track.png')
    });

    // Start playing it
    await TrackPlayer.play();
};
start();

Core Team


David Chavez

Special Thanks


Guilherme Chaguri


Dustin Bahr

Community

You can find us as part of the React Native Folks Discord in the #react-native-track-player channel.

 相关资料
  • 在android 12中更新应用程序后,尝试在android 12设备和模拟器中运行应用程序,但面临崩溃问题。 这就是问题所在。androidx.media.session。MediaButtonReceiver:Targeting S(版本31及以上)要求在存在意图过滤器时定义android:exported的显式值' 解决使用android:export=“true”修复了运行应用程序的问题,

  • 问题: 我可以构建React Native应用程序npx React Native run android,但当我安装React Native track player时,添加React Native track player它无法构建。 我所尝试的: (它不能安装我不知道为什么?(ERESOLVE无法解决依赖树)) 系统:Ubuntu和我都没有安装Watchman 错误: 本地运行 运行jeti

  • 本文向大家介绍react-native 启动React Native Packager,包括了react-native 启动React Native Packager的使用技巧和注意事项,需要的朋友参考一下 示例 在最新版本的React Native上,无需运行打包程序。它将自动运行。 默认情况下,这将在端口8081上启动服务器。要指定服务器所在的端口            

  • 百度移动统计SDK支持使用react native框架的H5页面统计,封装好的插件已经在github上开源,相关用法具体请参考:https://github.com/BaiduMobileAnalysis/baidumobstat-react-native。

  • The React Native environment has a lot of little quirks, so this documentation is aimed at helping smooth those over. Please feel free to create issues on GitHub for recommendations and additions to t

  • React Native 可以基于目前大热的开源JavaScript库React.js来开发iOS和Android原生App。而且React Native已经用于生产环境——Facebook Groups iOS 应用就是基于它开发的。 React Native的原理是在JavaScript中用React抽象操作系统原生的UI组件,代替DOM元素来渲染,比如以<View>取代<div>,以<Ima