1

I am trying play music from local storage

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

TrackPlayer.play();

But it didn't playing ,its working fine when i pass any cloud music link like (https://drive.google.com/uc?export=download&id=1V-c_WmanMA9i5BwfkmTs-605BQDsfyzC ).

here is code :

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;

mainly I need to play music from android local storage.

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
  • Please could you add the specific error you are getting, logs, output, etc.? – ainsausti Aug 29 '20 at 10:36
  • code not genrate any error logs it's working fine with cloud music url . i am getting problem when i add url: "file:///storage/emulated/0/Music/Galliyan___Heart_Touching_Ringtone.mp3" to play from local android storage. – Sanjiv kumar pandit Aug 30 '20 at 03:34
  • But what happens when you try to play this music from the local android storage, it simply shows as it is playing but you can't hear anything? The player doesn't show up? Don't you get any logs (even if it is not an error) when you are trying to play this? More information will help others to understand what's happening. – ainsausti Aug 31 '20 at 09:08
  • yes, when i try to play this music from the local android storage, it simply shows as it is playing but you can't hear anything. – Sanjiv kumar pandit Sep 01 '20 at 11:09
  • @Sanjivkumarpandit same error :( did you find any solutions? – Quang Thái Sep 17 '20 at 07:40
  • no, if you will getting any solutions please answer . – Sanjiv kumar pandit Sep 30 '20 at 04:30
  • Have a look at this comment it will solve your problem... https://stackoverflow.com/a/58761220/15536062 – Abhishek Jaiswal Dec 11 '21 at 20:00

0 Answers0