@@ -13,9 +13,11 @@ import { GetDownloadPath } from "../../LocalStorage/AppSettings";
1313import DeviceInfo from "react-native-device-info" ;
1414import { AddSongsToQueue , getIndexQuality } from "../../MusicPlayerFunctions" ;
1515import Context from "../../Context/Context" ;
16+ import TrackPlayer from "react-native-track-player" ;
1617
1718export const EachSongMenuModal = ( { Visible, setVisible} ) => {
1819 const { updateTrack} = useContext ( Context )
20+
1921 async function actualDownload ( ) {
2022 let dirs = ReactNativeBlobUtil . fs . dirs
2123 const path = await GetDownloadPath ( )
@@ -46,7 +48,48 @@ export const EachSongMenuModal = ({Visible, setVisible}) => {
4648 } )
4749 setVisible ( { visible : false } )
4850 }
49-
51+ async function playNext ( ) {
52+ const quality = await getIndexQuality ( )
53+ const song = {
54+ url : Visible . url [ quality ] . url ,
55+ title : FormatTitleAndArtist ( Visible . title ) ,
56+ artist : FormatTitleAndArtist ( Visible . artist ) ,
57+ artwork : Visible . image ,
58+ duration : Visible . duration ,
59+ id : Visible . id ,
60+ language : Visible . language ,
61+ image : Visible . image ,
62+ downloadUrl : Visible . url ,
63+ }
64+
65+ try {
66+ const queue = await TrackPlayer . getQueue ( ) ;
67+ const currentIndex = await TrackPlayer . getCurrentTrack ( ) ;
68+
69+ // If no track is playing, add to beginning and play
70+ if ( currentIndex === null || queue . length === 0 ) {
71+ await TrackPlayer . add ( song ) ;
72+ await TrackPlayer . play ( ) ;
73+ } else {
74+ await TrackPlayer . add ( song , currentIndex + 1 ) ;
75+ }
76+
77+ updateTrack ( ) ;
78+ setVisible ( { visible : false } ) ;
79+ ToastAndroid . showWithGravity (
80+ `Song Will Play Next` ,
81+ ToastAndroid . SHORT ,
82+ ToastAndroid . CENTER ,
83+ ) ;
84+ } catch ( error ) {
85+ console . log ( "Play next error:" , error ) ;
86+ ToastAndroid . showWithGravity (
87+ `Unable to add song` ,
88+ ToastAndroid . SHORT ,
89+ ToastAndroid . CENTER ,
90+ ) ;
91+ }
92+ }
5093 const getPermission = async ( ) => {
5194 if ( Platform . OS === 'ios' ) {
5295 actualDownload ( ) ;
@@ -94,78 +137,98 @@ export const EachSongMenuModal = ({Visible, setVisible}) => {
94137 }
95138 const size = Dimensions . get ( "window" ) . height
96139 return (
97- < Modal onBackButtonPress = { ( ) => setVisible ( { visible : false } ) } onSwipeComplete = { ( ) => setVisible ( { visible : false } ) } onBackdropPress = { ( ) => setVisible ( { visible : false } ) } swipeDirection = { [ 'up' , 'left' , 'right' , 'down' ] } isVisible = { Visible . visible } style = { {
98- justifyContent : 'flex-end' ,
99- margin : 0 ,
100- } } >
140+ < Modal
141+ onBackButtonPress = { ( ) => setVisible ( { visible : false } ) }
142+ onBackdropPress = { ( ) => setVisible ( { visible : false } ) }
143+ isVisible = { Visible . visible }
144+ backdropOpacity = { 0 }
145+ animationIn = "fadeIn"
146+ animationOut = "fadeOut"
147+ animationInTiming = { 50 }
148+ animationOutTiming = { 50 }
149+ useNativeDriver
150+ hideModalContentWhileAnimating
151+ style = { {
152+ margin : 0 ,
153+ position : 'absolute' ,
154+ top : typeof Visible . position ?. y === 'number' ? Visible . position . y : 0 ,
155+ right : 16 ,
156+ justifyContent : 'flex-start' ,
157+ } }
158+ >
101159 < View style = { {
102- backgroundColor :"rgb(18,18,18)" ,
103- elevation :10 ,
160+ backgroundColor : "rgb(28,28,28)" ,
161+ borderRadius : 10 ,
162+ width : 200 ,
163+ overflow : 'hidden' ,
164+ elevation : 10 ,
165+ transform : [
166+ { translateY : - 50 } ,
167+ { scale : Visible . visible ? 1 : 0.95 }
168+ ] ,
169+ opacity : Visible . visible ? 1 : 0 ,
104170 } } >
105- < Spacer />
106- < View
107- style = { {
108- flexDirection : 'row' ,
109- justifyContent :"space-between" ,
110- paddingHorizontal :15 ,
111- paddingTop :5 ,
112- alignItems :"center" ,
113- gap :10 ,
114- } } >
115- < View style = { {
116- flexDirection :"row" ,
117- flex :1 ,
118- } } >
119- < FastImage
120- source = { {
121- uri : Visible . image ?? "https://htmlcolorcodes.com/assets/images/colors/gray-color-solid-background-1920x1080.png" ,
122- } }
123- style = { {
124- height : ( size * 0.1 ) - 30 ,
125- width : ( size * 0.1 ) - 30 ,
126- borderRadius : 10 ,
127- } }
128- />
129- < View style = { {
130- flex :1 ,
131- height :( size * 0.1 ) - 30 ,
132- alignItems :"flex-start" ,
133- justifyContent :"center" ,
134- paddingHorizontal :10 ,
135- } } >
136- < PlainText text = { FormatTitleAndArtist ( Visible ?. title ) ?? "No music :(" } style = { { color :"white" } } />
137- < SmallText text = { FormatTitleAndArtist ( Visible ?. artist ) ?? "Explore now!" } maxLine = { 1 } />
138- </ View >
139- </ View >
140- </ View >
141- < Spacer />
142- < View style = { {
143- flexDirection :"row" ,
144- gap :10 ,
145- paddingHorizontal :10 ,
146- } } >
147- < EachModalButton text = { "Add to Queue" } icon = { < MaterialCommunityIcons name = { "playlist-music-outline" } size = { 25 } color = { "white" } /> } Onpress = { addSongToQueue } />
148- < EachModalButton text = { "Download" } Onpress = { getPermission } icon = { < AntDesign name = { "download" } size = { 25 } color = { "white" } /> } />
149- </ View >
150- < Spacer />
151- < Spacer />
152- < Spacer />
171+ { /* <MenuButton
172+ icon={<MaterialCommunityIcons name="magnify" size={22} color="white"/>}
173+ text="Search Home"
174+ onPress={() => {
175+ setVisible({visible: false});
176+ }}
177+ /> */ }
178+ < MenuButton
179+ icon = { < MaterialCommunityIcons name = "play-box-multiple" size = { 22 } color = "white" /> }
180+ text = "Play Next"
181+ onPress = { playNext }
182+ />
183+ < MenuButton
184+ icon = { < MaterialCommunityIcons name = "playlist-music" size = { 22 } color = "white" /> }
185+ text = "Add to Queue"
186+ onPress = { addSongToQueue }
187+ />
188+ { /* <MenuButton
189+ icon={<MaterialCommunityIcons name="playlist-plus" size={22} color="white"/>}
190+ text="Add to Playlist"
191+ onPress={() =>
192+ /> */ }
193+ < MenuButton
194+ icon = { < MaterialCommunityIcons name = "download" size = { 22 } color = "white" /> }
195+ text = "Download"
196+ onPress = { getPermission }
197+ />
198+ { /* <MenuButton
199+ icon={<MaterialCommunityIcons name="youtube" size={22} color="white"/>}
200+ text="Watch Video"
201+ onPress={() => {}}
202+ />
203+ <MenuButton
204+ icon={<MaterialCommunityIcons name="share-variant" size={22} color="white"/> }
205+ text="Share"
206+ onPress={() => {}}
207+ /> */ }
153208 </ View >
154209 </ Modal >
155210 ) ;
156211} ;
157- function EachModalButton ( { icon, text, Onpress} ) {
158- return < Pressable onPress = { ( ) => Onpress ( ) } style = { {
159- height :100 ,
160- backgroundColor :"rgb(41,47,49)" ,
161- borderRadius :10 ,
162- flex :1 ,
163- alignItems :"center" ,
164- justifyContent :"center" ,
165- elevation :5 ,
166- } } >
212+
213+ const MenuButton = ( { icon, text, onPress} ) => (
214+ < Pressable
215+ onPress = { onPress }
216+ android_ripple = { { color : 'rgba(255,255,255,0.1)' } }
217+ style = { {
218+ flexDirection : 'row' ,
219+ alignItems : 'center' ,
220+ padding : 12 ,
221+ paddingHorizontal : 16 ,
222+ } }
223+ >
167224 { icon }
168- < Spacer />
169- < PlainText text = { text } style = { { color :"white" , paddingRight :0 } } />
225+ < PlainText
226+ text = { text }
227+ style = { {
228+ color : "white" ,
229+ marginLeft : 16 ,
230+ fontSize : 14 ,
231+ } }
232+ />
170233 </ Pressable >
171- }
234+ ) ;
0 commit comments