Browse Source

Initial commit

master
Amir Savand 1 year ago
commit
0c49453fa4
9 changed files with 278 additions and 0 deletions
  1. 12
    0
      .editorconfig
  2. 2
    0
      .gitignore
  3. 6
    0
      .vscode/settings.json
  4. 33
    0
      app/app.css
  5. 64
    0
      app/app.html
  6. 40
    0
      app/app.js
  7. BIN
      app/app.png
  8. 101
    0
      main.js
  9. 20
    0
      package.json

+ 12
- 0
.editorconfig View File

@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false

[*.css]
indent_size = 4

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
node_modules/
package-lock.json

+ 6
- 0
.vscode/settings.json View File

@@ -0,0 +1,6 @@
{
"files.exclude": {
"node_modules/": true,
".vscode/": true
}
}

+ 33
- 0
app/app.css View File

@@ -0,0 +1,33 @@
body {
font-family: "Ubuntu";
background-color: #333;
color: #AAA;
cursor: default;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

body::-webkit-scrollbar {
background: #333;
}

body::-webkit-scrollbar {
width: 6px;
height: 6px;
}

body::-webkit-scrollbar-thumb {
background: #444;
}

.row {
margin: 0;
}

.progress {
border-radius: 0;
}

+ 64
- 0
app/app.html View File

@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Electro Music</title>

<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="../node_modules/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="app.css">

<script src="../node_modules/angular/angular.js"></script>
<script src="../node_modules/angular-soundmanager2/dist/angular-soundmanager2.js"></script>
<script src="app.js"></script>
</head>

<body ng-app="electro-music" ng-controller="MainController">

<!-- Initial sound manager -->
<sound-manager></sound-manager>

<!-- Song list -->
<ul class="list-group list-group-flush">
<a href="#" class="list-group-item bg-dark text-light" ng-repeat="song in shared.files | limitTo:10" music-player="play" add-song="song">
{{ song.artist }} &bull; {{ song.title }}
<i ng-if="currentPlaying.id === song.id" class="float-right fa fa-play-circle mt-1"></i>
</a>
</ul>

<!-- Current song -->
<div class="text-center mt-2" ng-if="currentPlaying">
<!-- Aritist and title -->
{{ currentPlaying.artist }} &bull; {{ currentPlaying.title }}<br>
<!-- Position and duration -->
<small>{{ currentPostion }} / {{ currentDuration }}</small>
</div>

<!-- Controls -->
<div class="text-center">
<!-- Prev -->
<button class="btn btn-lg btn-outline-light border-circle m-2" prev-track>
<i class="fa fa-backward"></i>
</button>
<!-- Play -->
<button class="btn btn-lg btn-light border-circle m-2" play-music ng-if="!isPlaying">
<i class="fa fa-play"></i>
</button>
<!-- Pause -->
<button class="btn btn-lg btn-light border-circle m-2" pause-music ng-if="isPlaying">
<i class="fa fa-pause"></i>
</button>
<!-- Next -->
<button class="btn btn-lg btn-outline-light border-circle m-2" next-track>
<i class="fa fa-forward"></i>
</button>
</div>

<!-- Progress -->
<div class="progress bg-dark mt-2" style="height: 5px;">
<div class="progress-bar bg-warning" style="width: {{ progress }}%"></div>
</div>
</body>

</html>

+ 40
- 0
app/app.js View File

@@ -0,0 +1,40 @@
var electron = require("electron");
var currentWindow = electron.remote.getCurrentWindow();
var app = angular.module("electro-music", ["angularSoundManager"]);

/**
* Main controller
*/
app.controller("MainController", function ($scope, angularPlayer) {

// Store shared data
$scope.shared = currentWindow.shared;

// Repeat by default
angularPlayer.repeatToggle();

/**
* On angular player ready
*/
$scope.$on("angularPlayer:ready", function (event, data) {
// Add all files to playlist
angular.forEach($scope.shared.files, function (file, index) {
angularPlayer.addTrack(file);
});
// Auto play
angularPlayer.play();
});
});

/**
* Duration filter
*/
app.filter("duration", function ($filter) {
return function (seconds) {
var output = $filter("date")(new Date(0, 0, 0).setSeconds(seconds), "HH:mm:ss");
if (output.toString().indexOf("00:") === 0) {
output = $filter("date")(new Date(0, 0, 0).setSeconds(seconds), "mm:ss");
}
return output;
};
})

BIN
app/app.png View File


+ 101
- 0
main.js View File

@@ -0,0 +1,101 @@
const { app, BrowserWindow } = require("electron")
const fs = require("fs")

/**
* @type {Electron.BrowserWindow}
*/
let win

/**
* @type {string}
*/
let musicPath = app.getPath("music")

/**
* @type {object}
*/
let shared = {
path: musicPath,
files: []
}

/**
* Store all files in music path and sub folders
*/
let getFiles = function (path) {
// Get all files and folders in path
fs.readdir(path, function (error, files) {
if (error) {
console.log(error);
} else {
// For each file and folder in directory
for (let file of files) {
// Get path
let filePath = path + "/" + file;
// Is a directory?
if (fs.statSync(filePath).isDirectory()) {
// Read it's files and folders again
getFiles(filePath);
}
// Is a file and has mp3 ext?
else if (file.indexOf(".mp3") !== -1) {
// Store to files
if (shared.files.length < 10) {
shared.files.push({
id: file,
path: filePath,
url: "file://" + filePath,
artist: "Artist",
title: file
});
}
}
}
}
});
}

app.on("ready", () => {

// Get all music files
getFiles(musicPath);

// Start window
win = new BrowserWindow({
width: 480,
height: 720,
minWidth: 400,
minHeight: 300,
autoHideMenuBar: true,
titleBarStyle: "hidden",
title: "Electro Music",
icon: "./app/app.png",
backgroundColor: "#333"
})

// Share shared data
win.shared = shared;

// Open inspector
// win.webContents.openDevTools();

// Load the HTML file
win.loadFile("./app/app.html")

// Clear win variable on close
win.on("closed", () => {
win = null
})
})

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit()
}
})

app.on("activate", () => {
if (win === null) {
createWindow()
}
})

+ 20
- 0
package.json View File

@@ -0,0 +1,20 @@
{
"name": "electron-music",
"version": "0.1.0",
"description": "Simple music player to learn more about electron.",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "^2.0.2"
},
"author": "Amir Savand",
"license": "MIT",
"dependencies": {
"angular": "^1.7.2",
"angular-soundmanager2": "Qleek/angular-soundmanager2#0040cab",
"bootstrap": "^4.1.1",
"font-awesome": "^4.7.0"
}
}

Loading…
Cancel
Save