-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding interactive seekbar
- Loading branch information
Showing
8 changed files
with
148 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from "react"; | ||
import { View } from "react-native"; | ||
import { | ||
faPause, | ||
faPlay, | ||
faReply, | ||
faSort, | ||
faStepBackward, | ||
faStepForward, | ||
faStop, | ||
faTrash, | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import { styles, BLUE, GRAY } from "../helpers/styles"; | ||
import { IconPress } from "./buttons"; | ||
|
||
const PlayerControls = ({ | ||
isPlaying, | ||
isLooping, | ||
previousTrack, | ||
playPause, | ||
stopPlayer, | ||
nextTrack, | ||
clearPlaylist, | ||
sortPlaylist, | ||
toggleLoop, | ||
}) => ( | ||
<View style={styles.playlistButtons}> | ||
<IconPress icon={faStepBackward} onPress={() => previousTrack()} /> | ||
<IconPress | ||
icon={isPlaying ? faPause : faPlay} | ||
onPress={() => playPause()} | ||
/> | ||
<IconPress | ||
icon={faStop} | ||
color={isPlaying ? BLUE : GRAY} | ||
onPress={() => stopPlayer()} | ||
/> | ||
<IconPress icon={faStepForward} onPress={() => nextTrack()} /> | ||
<IconPress | ||
icon={faReply} | ||
color={isLooping ? BLUE : GRAY} | ||
onPress={() => toggleLoop()} | ||
/> | ||
<IconPress icon={faSort} onPress={() => sortPlaylist()} /> | ||
<IconPress icon={faTrash} onPress={() => clearPlaylist()} /> | ||
</View> | ||
); | ||
|
||
export default PlayerControls; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
|
||
import { View, Text } from "react-native"; | ||
import Slider from "@react-native-community/slider"; | ||
import { styles, BLUE, GRAY } from "../helpers/styles"; | ||
|
||
function pad(n, width, z = 0) { | ||
n = n + ""; | ||
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; | ||
} | ||
|
||
const minutesAndSeconds = (position) => [ | ||
Math.floor(position / 60000, 0), | ||
pad(Math.floor((position / 1000) % 60, 2), 2), | ||
]; | ||
|
||
const SeekBar = ({ isPlaying, trackLength, currentPosition, onSeek, onSlidingStart }) => { | ||
const elapsed = minutesAndSeconds(currentPosition); | ||
const remaining = minutesAndSeconds(trackLength - currentPosition); | ||
return ( | ||
<View style={styles.deviceWidth}> | ||
<View style={{ flexDirection: "row" }}> | ||
<Text style={styles.text}>{elapsed[0] + ":" + elapsed[1]}</Text> | ||
<View style={{ flex: 1 }} /> | ||
<Text style={styles.text}> | ||
{trackLength > 1 && "-" + remaining[0] + ":" + remaining[1]} | ||
</Text> | ||
</View> | ||
<Slider | ||
style={styles.slider} | ||
disabled={!isPlaying} | ||
maximumValue={Math.max(trackLength, 1, currentPosition + 1)} | ||
onSlidingStart={onSlidingStart} | ||
onSlidingComplete={onSeek} | ||
value={currentPosition} | ||
minimumTrackTintColor={BLUE} | ||
maximumTrackTintColor={GRAY} | ||
thumbTintColor={isPlaying ? BLUE : GRAY} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
export default SeekBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters