1

我正在尝试从本地存储播放音乐

TrackPlayer.add({
      id: '1283',
      url: "file:///storage/emulated/0/Music/Galliyan___Heart_Touching_Ringtone.mp3",
    
    }); 

TrackPlayer.play();

但它没有播放,当我通过任何云音乐链接时它工作正常(https://drive.google.com/uc?export=download&id=1V-c_WmanMA9i5BwfkmTs-605BQDsfyzC)。

这是代码:

import TrackPlayer from 'react-native-track-player';
import React from 'react';
import {View, Text, StyleSheet, Image, TouchableOpacity} from 'react-native';
// Creates the player
const Player = () => {
  TrackPlayer.setupPlayer().then(async () => {
    // Adds a track to the queue
    await TrackPlayer.add({
      id: 'trackId',
      url: "https://drive.google.com/uc?export=download&id=1V-c_WmanMA9i5BwfkmTs-605BQDsfyzC",
      title: 'Track Title',
      artist: 'Track Artist',
      artwork: require('./static/refresh.png'),
    });
  });
  const playHandel = () => {
    TrackPlayer.play().then(()=>{
      console.log('played');
    }).catch(err=>{
      console.log(err)
    });
  };
  const pushHandel = () => {
    console.log('push');
    TrackPlayer.pause();
  };
  return (
    <>
      <View>
        <TouchableOpacity onPress={playHandel}>
          <Text>play</Text>
        </TouchableOpacity>
      </View>
      <View>
        <TouchableOpacity onPress={pushHandel}>
          <Text>push</Text>
        </TouchableOpacity>
      </View>
    </>
  );
};

export default Player;

主要是我需要从 android 本地存储播放音乐。

4

0 回答 0