Skip to content

Commit

Permalink
Merge pull request #4 from mp3chapters/DominikPeters/launch-player-wi…
Browse files Browse the repository at this point in the history
…th-mp3

Launch the player from command line with an MP3 file
  • Loading branch information
DominikPeters authored Nov 16, 2024
2 parents 50cddfa + 5440a8f commit 2b93510
Show file tree
Hide file tree
Showing 6 changed files with 857 additions and 522 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# MP3 Chapters Player

A simple desktop application to play MP3 files with chapters.
A simple desktop application to play MP3 files with chapters.

The player can also be started from the command line, by passing a path to the desired MP3 file.

```sh
"MP3 Chapter Player.exe" "c:\path\to\file.mp3"
```
43 changes: 23 additions & 20 deletions src-app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@ import { invoke } from '@tauri-apps/api/tauri';
import { open } from '@tauri-apps/api/dialog';
import { appWindow } from "@tauri-apps/api/window";
import { convertFileSrc } from '@tauri-apps/api/tauri';
import { listen } from '@tauri-apps/api/event'
import { getMatches } from '@tauri-apps/api/cli';

import { loadFile } from '@common/FileLoader.js';
import { startUp } from '@common/Player.js';

function handleMP3FilePath(filePath) {
const url = convertFileSrc(filePath);
console.log("Opening file: " + url);
player.src = { src: url, type: 'audio/mpeg' };
loadFile(player, url);
const fileName = filePath.split('\\').pop().split('/').pop();
appWindow.setTitle(fileName);
}

listen('tauri://file-drop', event => {
console.log(event);
const filesDrop = event.payload;
for (let file of filesDrop) {
if (file.endsWith('.mp3')) {
const url = convertFileSrc(file);
console.log(url);
player.src = { src: url, type: 'audio/mpeg' };
loadFile(player, url);
const fileName = file.split('\\').pop().split('/').pop();
appWindow.setTitle(fileName);
handleMP3FilePath(file);
break;
}
}
Expand All @@ -37,12 +41,9 @@ async function openFile() {
],
});
console.log(selected);
const url = convertFileSrc(selected);
console.log(url);
player.src = { src: url, type: 'audio/mpeg' };
loadFile(player, url);
const fileName = selected.split('\\').pop().split('/').pop();
appWindow.setTitle(fileName);
if (selected) {
handleMP3FilePath(selected);
}
}

const unlisten = await appWindow.onMenuClicked(async ({ payload: menuId }) => {
Expand All @@ -56,11 +57,13 @@ const player = document.querySelector("media-player");

startUp();

window.addEventListener("DOMContentLoaded", async () => {
// greetInputEl = document.querySelector("#greet-input");
// greetMsgEl = document.querySelector("#greet-msg");
// document.querySelector("#greet-form").addEventListener("submit", (e) => {
// e.preventDefault();
// greet();
// });
// reading arguments from the command line
getMatches().then((matches) => {
console.log("Matches:");
console.log(matches);
window.matches = matches;
if (matches.args.filename.value) {
console.log(matches.args.filename.value);
handleMP3FilePath(matches.args.filename.value);
}
});
Loading

0 comments on commit 2b93510

Please sign in to comment.