Compare commits
9
Commits
046bf6afe4
...
v0.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c02469c6d0 | ||
|
|
1b7b836b3e | ||
|
|
609a16f468 | ||
|
|
c967b062a2 | ||
|
|
a8e0dcaf37 | ||
|
|
09808a2136 | ||
|
|
8b51a910f5 | ||
|
|
9723c13bd3 | ||
|
|
52120529ff |
@@ -21,11 +21,6 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup .NET 9
|
|
||||||
uses: actions/setup-dotnet@v4
|
|
||||||
with:
|
|
||||||
dotnet-version: '9.0.x'
|
|
||||||
|
|
||||||
- name: Verify .NET installation
|
- name: Verify .NET installation
|
||||||
run: dotnet --version
|
run: dotnet --version
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,6 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup .NET 9
|
|
||||||
uses: actions/setup-dotnet@v4
|
|
||||||
with:
|
|
||||||
dotnet-version: '9.0.x'
|
|
||||||
|
|
||||||
- name: Verify .NET installation
|
- name: Verify .NET installation
|
||||||
run: dotnet --version
|
run: dotnet --version
|
||||||
|
|
||||||
|
|||||||
@@ -62,4 +62,24 @@ public class PluginConfiguration : BasePluginConfiguration
|
|||||||
/// Gets or sets the Jellyfin API key for authenticating stream requests from LMS.
|
/// Gets or sets the Jellyfin API key for authenticating stream requests from LMS.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string JellyfinApiKey { get; set; } = string.Empty;
|
public string JellyfinApiKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether to use direct file paths instead of HTTP streaming.
|
||||||
|
/// When enabled, LMS accesses files directly from shared storage, enabling native seeking.
|
||||||
|
/// </summary>
|
||||||
|
public bool UseDirectFilePath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the media path prefix as seen by Jellyfin.
|
||||||
|
/// Used for path mapping when UseDirectFilePath is enabled.
|
||||||
|
/// Example: /media/music or C:\Music.
|
||||||
|
/// </summary>
|
||||||
|
public string JellyfinMediaPath { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the media path prefix as seen by LMS.
|
||||||
|
/// Used for path mapping when UseDirectFilePath is enabled.
|
||||||
|
/// Example: /mnt/music or //nas/music.
|
||||||
|
/// </summary>
|
||||||
|
public string LmsMediaPath { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,64 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>JellyLMS</title>
|
<title>JellyLMS</title>
|
||||||
|
<style>
|
||||||
|
.sync-group {
|
||||||
|
border: 2px solid #00a4dc;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 12px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
background: rgba(0, 164, 220, 0.05);
|
||||||
|
}
|
||||||
|
.sync-group-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.sync-group-players {
|
||||||
|
color: #ccc;
|
||||||
|
}
|
||||||
|
.player-sync-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px 0;
|
||||||
|
border-bottom: 1px solid #333;
|
||||||
|
}
|
||||||
|
.player-sync-row:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
.player-sync-checkbox {
|
||||||
|
margin-right: 12px;
|
||||||
|
}
|
||||||
|
.player-sync-name {
|
||||||
|
flex: 1;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.player-sync-status {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
.status-dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.status-dot.on { background: #52b54b; }
|
||||||
|
.status-dot.standby { background: #f9a825; }
|
||||||
|
.status-dot.off { background: #f44336; }
|
||||||
|
.sync-actions {
|
||||||
|
margin-top: 15px;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
#syncStatus {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="JellyLmsConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
|
<div id="JellyLmsConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
|
||||||
@@ -73,18 +131,6 @@
|
|||||||
</label>
|
</label>
|
||||||
<div class="fieldDescription checkboxFieldDescription">Automatically sync players when playing to multiple devices</div>
|
<div class="fieldDescription checkboxFieldDescription">Automatically sync players when playing to multiple devices</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="verticalSection">
|
|
||||||
<h3>LMS Players</h3>
|
|
||||||
<div id="playersList">
|
|
||||||
<p>Click "Refresh Players" to discover LMS players.</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<button is="emby-button" type="button" id="btnRefreshPlayers" class="raised button-alt block emby-button">
|
|
||||||
<span>Refresh Players</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="inputContainer" style="margin-top: 15px;">
|
<div class="inputContainer" style="margin-top: 15px;">
|
||||||
<label class="inputLabel inputLabelUnfocused" for="DefaultPlayerMac">Default Player</label>
|
<label class="inputLabel inputLabelUnfocused" for="DefaultPlayerMac">Default Player</label>
|
||||||
@@ -95,6 +141,56 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="verticalSection">
|
||||||
|
<h3>Direct File Access (Optional)</h3>
|
||||||
|
<p class="fieldDescription">If LMS and Jellyfin share the same storage (e.g., NAS), enable direct file access for native seeking support. This provides smooth seeking without audio restart.</p>
|
||||||
|
|
||||||
|
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||||
|
<label class="emby-checkbox-label">
|
||||||
|
<input id="UseDirectFilePath" name="UseDirectFilePath" type="checkbox" is="emby-checkbox" />
|
||||||
|
<span>Enable Direct File Access</span>
|
||||||
|
</label>
|
||||||
|
<div class="fieldDescription checkboxFieldDescription">When enabled, LMS will access files directly instead of streaming via HTTP</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="directPathSettings" style="margin-top: 15px;">
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="JellyfinMediaPath">Jellyfin Media Path</label>
|
||||||
|
<input id="JellyfinMediaPath" name="JellyfinMediaPath" type="text" is="emby-input" placeholder="/media/music" />
|
||||||
|
<div class="fieldDescription">The path prefix as Jellyfin sees your media library (e.g., /media/music)</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="LmsMediaPath">LMS Media Path</label>
|
||||||
|
<input id="LmsMediaPath" name="LmsMediaPath" type="text" is="emby-input" placeholder="/mnt/music" />
|
||||||
|
<div class="fieldDescription">The same location as LMS sees it (e.g., /mnt/music or //nas/music)</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="verticalSection">
|
||||||
|
<h3>Player Sync</h3>
|
||||||
|
<p class="fieldDescription">Select players to sync together for multi-room audio. Synced players play in perfect sync.</p>
|
||||||
|
|
||||||
|
<div id="currentSyncGroups">
|
||||||
|
<!-- Existing sync groups shown here -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="playerSyncList">
|
||||||
|
<p>Loading players...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sync-actions">
|
||||||
|
<button is="emby-button" type="button" id="btnSyncSelected" class="raised button-submit emby-button" disabled>
|
||||||
|
<span>Sync Selected</span>
|
||||||
|
</button>
|
||||||
|
<button is="emby-button" type="button" id="btnRefreshPlayers" class="raised button-alt emby-button">
|
||||||
|
<span>Refresh</span>
|
||||||
|
</button>
|
||||||
|
<span id="syncStatus"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
||||||
<span>Save</span>
|
<span>Save</span>
|
||||||
@@ -105,45 +201,34 @@
|
|||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var JellyLmsConfig = {
|
var JellyLmsConfig = {
|
||||||
pluginUniqueId: 'a5b8c9d0-1e2f-3a4b-5c6d-7e8f9a0b1c2d'
|
pluginUniqueId: 'a5b8c9d0-1e2f-3a4b-5c6d-7e8f9a0b1c2d',
|
||||||
|
players: [],
|
||||||
|
syncGroups: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getStatusClass(player) {
|
||||||
|
if (!player.IsConnected) return 'off';
|
||||||
|
return player.IsPoweredOn ? 'on' : 'standby';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatusText(player) {
|
||||||
|
if (!player.IsConnected) return 'Disconnected';
|
||||||
|
return player.IsPoweredOn ? 'On' : 'Standby';
|
||||||
|
}
|
||||||
|
|
||||||
function loadPlayers() {
|
function loadPlayers() {
|
||||||
var playersList = document.querySelector('#playersList');
|
|
||||||
var defaultSelect = document.querySelector('#DefaultPlayerMac');
|
var defaultSelect = document.querySelector('#DefaultPlayerMac');
|
||||||
var currentDefault = defaultSelect.value;
|
var currentDefault = defaultSelect.value;
|
||||||
|
|
||||||
playersList.innerHTML = '<p>Loading players...</p>';
|
|
||||||
|
|
||||||
ApiClient.ajax({
|
ApiClient.ajax({
|
||||||
url: ApiClient.getUrl('JellyLms/Players', { refresh: true }),
|
url: ApiClient.getUrl('JellyLms/Players', { refresh: true }),
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
}).then(function(players) {
|
}).then(function(players) {
|
||||||
|
JellyLmsConfig.players = players || [];
|
||||||
defaultSelect.innerHTML = '<option value="">None</option>';
|
defaultSelect.innerHTML = '<option value="">None</option>';
|
||||||
|
|
||||||
if (!players || players.length === 0) {
|
|
||||||
playersList.innerHTML = '<p>No players found. Make sure LMS is running and has connected players.</p>';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var html = '<table class="tblGenres detailTable" style="width: 100%;">';
|
|
||||||
html += '<thead><tr><th>Name</th><th>Model</th><th>Status</th><th>Volume</th><th>Synced</th></tr></thead>';
|
|
||||||
html += '<tbody>';
|
|
||||||
|
|
||||||
players.forEach(function(player) {
|
players.forEach(function(player) {
|
||||||
var status = player.IsConnected ? (player.IsPoweredOn ? 'On' : 'Standby') : 'Disconnected';
|
|
||||||
var statusColor = player.IsConnected ? (player.IsPoweredOn ? 'green' : 'orange') : 'red';
|
|
||||||
var syncStatus = player.IsSynced ? 'Yes' : 'No';
|
|
||||||
|
|
||||||
html += '<tr>';
|
|
||||||
html += '<td>' + player.Name + '</td>';
|
|
||||||
html += '<td>' + player.Model + '</td>';
|
|
||||||
html += '<td style="color: ' + statusColor + ';">' + status + '</td>';
|
|
||||||
html += '<td>' + player.Volume + '%</td>';
|
|
||||||
html += '<td>' + syncStatus + '</td>';
|
|
||||||
html += '</tr>';
|
|
||||||
|
|
||||||
var option = document.createElement('option');
|
var option = document.createElement('option');
|
||||||
option.value = player.MacAddress;
|
option.value = player.MacAddress;
|
||||||
option.text = player.Name;
|
option.text = player.Name;
|
||||||
@@ -153,14 +238,179 @@
|
|||||||
defaultSelect.appendChild(option);
|
defaultSelect.appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
html += '</tbody></table>';
|
renderPlayerList();
|
||||||
playersList.innerHTML = html;
|
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
playersList.innerHTML = '<p style="color: red;">Error loading players. Check LMS connection.</p>';
|
document.querySelector('#playerSyncList').innerHTML = '<p style="color: red;">Error loading players. Check LMS connection.</p>';
|
||||||
console.error('Error loading players:', err);
|
console.error('Error loading players:', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadSyncGroups() {
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/SyncGroups'),
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'json'
|
||||||
|
}).then(function(groups) {
|
||||||
|
JellyLmsConfig.syncGroups = groups || [];
|
||||||
|
renderSyncGroups();
|
||||||
|
renderPlayerList();
|
||||||
|
}).catch(function(err) {
|
||||||
|
console.error('Error loading sync groups:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSyncGroups() {
|
||||||
|
var container = document.querySelector('#currentSyncGroups');
|
||||||
|
var groups = JellyLmsConfig.syncGroups;
|
||||||
|
|
||||||
|
if (!groups || groups.length === 0) {
|
||||||
|
container.innerHTML = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = '';
|
||||||
|
groups.forEach(function(group) {
|
||||||
|
var playerNames = [];
|
||||||
|
var masterPlayer = JellyLmsConfig.players.find(function(p) { return p.MacAddress === group.MasterMac; });
|
||||||
|
if (masterPlayer) playerNames.push(masterPlayer.Name);
|
||||||
|
|
||||||
|
group.SlaveMacs.forEach(function(mac) {
|
||||||
|
var player = JellyLmsConfig.players.find(function(p) { return p.MacAddress === mac; });
|
||||||
|
if (player) playerNames.push(player.Name);
|
||||||
|
});
|
||||||
|
|
||||||
|
html += '<div class="sync-group">';
|
||||||
|
html += '<div class="sync-group-header">';
|
||||||
|
html += '<span class="sync-group-players">' + playerNames.join(' + ') + '</span>';
|
||||||
|
html += '<button is="emby-button" type="button" class="raised button-alt emby-button btnUnsyncGroup" data-master="' + group.MasterMac + '">';
|
||||||
|
html += '<span>Unsync</span>';
|
||||||
|
html += '</button>';
|
||||||
|
html += '</div>';
|
||||||
|
html += '</div>';
|
||||||
|
});
|
||||||
|
|
||||||
|
container.innerHTML = html;
|
||||||
|
|
||||||
|
container.querySelectorAll('.btnUnsyncGroup').forEach(function(btn) {
|
||||||
|
btn.addEventListener('click', function() {
|
||||||
|
unsyncGroup(this.getAttribute('data-master'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderPlayerList() {
|
||||||
|
var container = document.querySelector('#playerSyncList');
|
||||||
|
var players = JellyLmsConfig.players;
|
||||||
|
|
||||||
|
if (!players || players.length === 0) {
|
||||||
|
container.innerHTML = '<p>No players found. Make sure LMS is running.</p>';
|
||||||
|
updateSyncButton();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get MACs of already synced players
|
||||||
|
var syncedMacs = new Set();
|
||||||
|
JellyLmsConfig.syncGroups.forEach(function(group) {
|
||||||
|
syncedMacs.add(group.MasterMac);
|
||||||
|
group.SlaveMacs.forEach(function(mac) { syncedMacs.add(mac); });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Only show unsynced players
|
||||||
|
var unsyncedPlayers = players.filter(function(p) {
|
||||||
|
return !syncedMacs.has(p.MacAddress);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (unsyncedPlayers.length === 0) {
|
||||||
|
container.innerHTML = '<p>All players are synced.</p>';
|
||||||
|
updateSyncButton();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = '';
|
||||||
|
unsyncedPlayers.forEach(function(player) {
|
||||||
|
var statusClass = getStatusClass(player);
|
||||||
|
html += '<div class="player-sync-row">';
|
||||||
|
html += '<input type="checkbox" class="player-sync-checkbox" data-mac="' + player.MacAddress + '" id="sync-' + player.MacAddress + '">';
|
||||||
|
html += '<label class="player-sync-name" for="sync-' + player.MacAddress + '">' + player.Name + '</label>';
|
||||||
|
html += '<div class="player-sync-status">';
|
||||||
|
html += '<span class="status-dot ' + statusClass + '"></span>';
|
||||||
|
html += '<span>' + getStatusText(player) + '</span>';
|
||||||
|
html += '</div>';
|
||||||
|
html += '</div>';
|
||||||
|
});
|
||||||
|
|
||||||
|
container.innerHTML = html;
|
||||||
|
|
||||||
|
// Add change listeners
|
||||||
|
container.querySelectorAll('.player-sync-checkbox').forEach(function(cb) {
|
||||||
|
cb.addEventListener('change', updateSyncButton);
|
||||||
|
});
|
||||||
|
|
||||||
|
updateSyncButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSelectedMacs() {
|
||||||
|
var checkboxes = document.querySelectorAll('.player-sync-checkbox:checked');
|
||||||
|
var macs = [];
|
||||||
|
checkboxes.forEach(function(cb) {
|
||||||
|
macs.push(cb.getAttribute('data-mac'));
|
||||||
|
});
|
||||||
|
return macs;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSyncButton() {
|
||||||
|
var btn = document.querySelector('#btnSyncSelected');
|
||||||
|
var selected = getSelectedMacs();
|
||||||
|
btn.disabled = selected.length < 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncSelected() {
|
||||||
|
var macs = getSelectedMacs();
|
||||||
|
if (macs.length < 2) return;
|
||||||
|
|
||||||
|
var statusDiv = document.querySelector('#syncStatus');
|
||||||
|
statusDiv.innerHTML = '<span style="color: orange;">Syncing...</span>';
|
||||||
|
|
||||||
|
// First MAC becomes master (arbitrary, user doesn't need to know)
|
||||||
|
var masterMac = macs[0];
|
||||||
|
var slaveMacs = macs.slice(1);
|
||||||
|
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/SyncGroups'),
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({
|
||||||
|
MasterMac: masterMac,
|
||||||
|
SlaveMacs: slaveMacs
|
||||||
|
})
|
||||||
|
}).then(function() {
|
||||||
|
statusDiv.innerHTML = '<span style="color: green;">Synced!</span>';
|
||||||
|
setTimeout(function() {
|
||||||
|
statusDiv.innerHTML = '';
|
||||||
|
loadSyncGroups();
|
||||||
|
}, 1500);
|
||||||
|
}).catch(function(err) {
|
||||||
|
statusDiv.innerHTML = '<span style="color: red;">Failed to sync.</span>';
|
||||||
|
console.error('Error syncing:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function unsyncGroup(masterMac) {
|
||||||
|
var statusDiv = document.querySelector('#syncStatus');
|
||||||
|
statusDiv.innerHTML = '<span style="color: orange;">Unsyncing...</span>';
|
||||||
|
|
||||||
|
ApiClient.ajax({
|
||||||
|
url: ApiClient.getUrl('JellyLms/SyncGroups/' + encodeURIComponent(masterMac)),
|
||||||
|
type: 'DELETE'
|
||||||
|
}).then(function() {
|
||||||
|
statusDiv.innerHTML = '';
|
||||||
|
loadSyncGroups();
|
||||||
|
}).catch(function(err) {
|
||||||
|
statusDiv.innerHTML = '<span style="color: red;">Failed to unsync.</span>';
|
||||||
|
console.error('Error unsyncing:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function testConnection() {
|
function testConnection() {
|
||||||
var statusDiv = document.querySelector('#connectionStatus');
|
var statusDiv = document.querySelector('#connectionStatus');
|
||||||
statusDiv.innerHTML = '<span style="color: orange;">Testing connection...</span>';
|
statusDiv.innerHTML = '<span style="color: orange;">Testing connection...</span>';
|
||||||
@@ -173,6 +423,7 @@
|
|||||||
if (result.IsConnected) {
|
if (result.IsConnected) {
|
||||||
statusDiv.innerHTML = '<span style="color: green;">Connected! Found ' + result.PlayerCount + ' player(s).</span>';
|
statusDiv.innerHTML = '<span style="color: green;">Connected! Found ' + result.PlayerCount + ' player(s).</span>';
|
||||||
loadPlayers();
|
loadPlayers();
|
||||||
|
loadSyncGroups();
|
||||||
} else {
|
} else {
|
||||||
statusDiv.innerHTML = '<span style="color: red;">Connection failed: ' + (result.LastError || 'Unknown error') + '</span>';
|
statusDiv.innerHTML = '<span style="color: red;">Connection failed: ' + (result.LastError || 'Unknown error') + '</span>';
|
||||||
}
|
}
|
||||||
@@ -194,7 +445,13 @@
|
|||||||
document.querySelector('#ConnectionTimeoutSeconds').value = config.ConnectionTimeoutSeconds || 10;
|
document.querySelector('#ConnectionTimeoutSeconds').value = config.ConnectionTimeoutSeconds || 10;
|
||||||
document.querySelector('#EnableAutoSync').checked = config.EnableAutoSync !== false;
|
document.querySelector('#EnableAutoSync').checked = config.EnableAutoSync !== false;
|
||||||
document.querySelector('#DefaultPlayerMac').value = config.DefaultPlayerMac || '';
|
document.querySelector('#DefaultPlayerMac').value = config.DefaultPlayerMac || '';
|
||||||
|
document.querySelector('#UseDirectFilePath').checked = config.UseDirectFilePath || false;
|
||||||
|
document.querySelector('#JellyfinMediaPath').value = config.JellyfinMediaPath || '';
|
||||||
|
document.querySelector('#LmsMediaPath').value = config.LmsMediaPath || '';
|
||||||
Dashboard.hideLoadingMsg();
|
Dashboard.hideLoadingMsg();
|
||||||
|
|
||||||
|
loadPlayers();
|
||||||
|
loadSyncGroups();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -213,6 +470,12 @@
|
|||||||
document.querySelector('#btnRefreshPlayers')
|
document.querySelector('#btnRefreshPlayers')
|
||||||
.addEventListener('click', function() {
|
.addEventListener('click', function() {
|
||||||
loadPlayers();
|
loadPlayers();
|
||||||
|
loadSyncGroups();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#btnSyncSelected')
|
||||||
|
.addEventListener('click', function() {
|
||||||
|
syncSelected();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector('#JellyLmsConfigForm')
|
document.querySelector('#JellyLmsConfigForm')
|
||||||
@@ -227,6 +490,9 @@
|
|||||||
config.ConnectionTimeoutSeconds = parseInt(document.querySelector('#ConnectionTimeoutSeconds').value) || 10;
|
config.ConnectionTimeoutSeconds = parseInt(document.querySelector('#ConnectionTimeoutSeconds').value) || 10;
|
||||||
config.EnableAutoSync = document.querySelector('#EnableAutoSync').checked;
|
config.EnableAutoSync = document.querySelector('#EnableAutoSync').checked;
|
||||||
config.DefaultPlayerMac = document.querySelector('#DefaultPlayerMac').value;
|
config.DefaultPlayerMac = document.querySelector('#DefaultPlayerMac').value;
|
||||||
|
config.UseDirectFilePath = document.querySelector('#UseDirectFilePath').checked;
|
||||||
|
config.JellyfinMediaPath = document.querySelector('#JellyfinMediaPath').value;
|
||||||
|
config.LmsMediaPath = document.querySelector('#LmsMediaPath').value;
|
||||||
ApiClient.updatePluginConfiguration(JellyLmsConfig.pluginUniqueId, config).then(function (result) {
|
ApiClient.updatePluginConfiguration(JellyLmsConfig.pluginUniqueId, config).then(function (result) {
|
||||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -226,8 +226,10 @@ public class LmsApiClient : ILmsApiClient, IDisposable
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("LMS SeekAsync: player {Mac}, position {Seconds}s", playerMac, positionSeconds);
|
||||||
await SendCommandAsync<object>(playerMac, ["time", positionSeconds.ToString("F1", CultureInfo.InvariantCulture)])
|
await SendCommandAsync<object>(playerMac, ["time", positionSeconds.ToString("F1", CultureInfo.InvariantCulture)])
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
_logger.LogInformation("LMS SeekAsync: command sent successfully");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -178,12 +178,15 @@ public class LmsDeviceDiscoveryService : IHostedService, IDisposable
|
|||||||
var isNew = !_registeredDeviceIds.ContainsKey(player.MacAddress);
|
var isNew = !_registeredDeviceIds.ContainsKey(player.MacAddress);
|
||||||
|
|
||||||
// Add our controller to the session using EnsureController pattern
|
// Add our controller to the session using EnsureController pattern
|
||||||
|
var libraryManager = _serviceProvider.GetRequiredService<ILibraryManager>();
|
||||||
var (controller, created) = session.EnsureController<LmsSessionController>(
|
var (controller, created) = session.EnsureController<LmsSessionController>(
|
||||||
s => new LmsSessionController(
|
s => new LmsSessionController(
|
||||||
_logger,
|
_logger,
|
||||||
_lmsClient,
|
_lmsClient,
|
||||||
player,
|
player,
|
||||||
s));
|
s,
|
||||||
|
sessionManager,
|
||||||
|
libraryManager));
|
||||||
|
|
||||||
if (created)
|
if (created)
|
||||||
{
|
{
|
||||||
@@ -221,72 +224,6 @@ public class LmsDeviceDiscoveryService : IHostedService, IDisposable
|
|||||||
player.MacAddress,
|
player.MacAddress,
|
||||||
session.Id);
|
session.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report playback progress if the controller has an active item
|
|
||||||
if (controller is LmsSessionController lmsController)
|
|
||||||
{
|
|
||||||
await ReportPlaybackProgressAsync(sessionManager, session, lmsController).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ReportPlaybackProgressAsync(
|
|
||||||
ISessionManager sessionManager,
|
|
||||||
SessionInfo session,
|
|
||||||
LmsSessionController controller)
|
|
||||||
{
|
|
||||||
if (!controller.IsPlaying || !controller.CurrentItemId.HasValue)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Get current playback status from LMS
|
|
||||||
var status = await _lmsClient.GetPlayerStatusAsync(controller.PlayerMac).ConfigureAwait(false);
|
|
||||||
if (status == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the item from Jellyfin library
|
|
||||||
var libraryManager = _serviceProvider.GetService<ILibraryManager>();
|
|
||||||
if (libraryManager == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var item = libraryManager.GetItemById(controller.CurrentItemId.Value);
|
|
||||||
if (item == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate position in ticks
|
|
||||||
var positionTicks = (long)(status.Time * TimeSpan.TicksPerSecond);
|
|
||||||
|
|
||||||
// Determine if paused
|
|
||||||
var isPaused = status.Mode == "pause";
|
|
||||||
|
|
||||||
// Create playback progress info
|
|
||||||
var progressInfo = new PlaybackProgressInfo
|
|
||||||
{
|
|
||||||
ItemId = controller.CurrentItemId.Value,
|
|
||||||
SessionId = session.Id,
|
|
||||||
IsPaused = isPaused,
|
|
||||||
PositionTicks = positionTicks,
|
|
||||||
PlayMethod = PlayMethod.DirectStream,
|
|
||||||
CanSeek = true,
|
|
||||||
IsMuted = status.Volume == 0,
|
|
||||||
VolumeLevel = status.Volume
|
|
||||||
};
|
|
||||||
|
|
||||||
// Report progress to session manager
|
|
||||||
await sessionManager.OnPlaybackProgress(progressInfo).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogDebug(ex, "Error reporting playback progress for player {Name}", controller.PlayerMac);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ using System.Text.Json;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Plugin.JellyLMS.Models;
|
using Jellyfin.Plugin.JellyLMS.Models;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Session;
|
using MediaBrowser.Controller.Session;
|
||||||
using MediaBrowser.Model.Session;
|
using MediaBrowser.Model.Session;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -13,12 +15,20 @@ namespace Jellyfin.Plugin.JellyLMS.Services;
|
|||||||
/// Session controller for LMS player devices.
|
/// Session controller for LMS player devices.
|
||||||
/// Enables Jellyfin to send playback commands to LMS players via the cast interface.
|
/// Enables Jellyfin to send playback commands to LMS players via the cast interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LmsSessionController : ISessionController
|
public class LmsSessionController : ISessionController, IDisposable
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly ILmsApiClient _lmsClient;
|
private readonly ILmsApiClient _lmsClient;
|
||||||
private readonly LmsPlayer _player;
|
private readonly LmsPlayer _player;
|
||||||
private readonly SessionInfo _session;
|
private readonly SessionInfo _session;
|
||||||
|
private readonly ISessionManager _sessionManager;
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
private Timer? _progressTimer;
|
||||||
|
private bool _disposed;
|
||||||
|
private BaseItem? _currentItem;
|
||||||
|
private Guid[] _playlist = [];
|
||||||
|
private int _playlistIndex;
|
||||||
|
private long _seekOffsetTicks; // Offset from transcoded stream start position
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="LmsSessionController"/> class.
|
/// Initializes a new instance of the <see cref="LmsSessionController"/> class.
|
||||||
@@ -27,16 +37,22 @@ public class LmsSessionController : ISessionController
|
|||||||
/// <param name="lmsClient">The LMS API client.</param>
|
/// <param name="lmsClient">The LMS API client.</param>
|
||||||
/// <param name="player">The LMS player this controller manages.</param>
|
/// <param name="player">The LMS player this controller manages.</param>
|
||||||
/// <param name="session">The Jellyfin session associated with this controller.</param>
|
/// <param name="session">The Jellyfin session associated with this controller.</param>
|
||||||
|
/// <param name="sessionManager">The session manager for reporting playback events.</param>
|
||||||
|
/// <param name="libraryManager">The library manager for item lookups.</param>
|
||||||
public LmsSessionController(
|
public LmsSessionController(
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
ILmsApiClient lmsClient,
|
ILmsApiClient lmsClient,
|
||||||
LmsPlayer player,
|
LmsPlayer player,
|
||||||
SessionInfo session)
|
SessionInfo session,
|
||||||
|
ISessionManager sessionManager,
|
||||||
|
ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_lmsClient = lmsClient;
|
_lmsClient = lmsClient;
|
||||||
_player = player;
|
_player = player;
|
||||||
_session = session;
|
_session = session;
|
||||||
|
_sessionManager = sessionManager;
|
||||||
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -73,10 +89,20 @@ public class LmsSessionController : ISessionController
|
|||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
"LMS Session Controller received message {MessageType} for player {PlayerName} ({Mac})",
|
"LMS Session Controller received message {MessageType} for player {PlayerName} ({Mac}), data type: {DataType}",
|
||||||
name,
|
name,
|
||||||
_player.Name,
|
_player.Name,
|
||||||
_player.MacAddress);
|
_player.MacAddress,
|
||||||
|
data?.GetType().Name ?? "null");
|
||||||
|
|
||||||
|
// Log the data for debugging
|
||||||
|
if (data is PlaystateRequest psr)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"PlaystateRequest: Command={Command}, SeekPositionTicks={Ticks}",
|
||||||
|
psr.Command,
|
||||||
|
psr.SeekPositionTicks);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -124,14 +150,41 @@ public class LmsSessionController : ISessionController
|
|||||||
await _lmsClient.PowerOnAsync(_player.MacAddress).ConfigureAwait(false);
|
await _lmsClient.PowerOnAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For now, play the first item
|
|
||||||
// TODO: Support playlists/queues
|
|
||||||
if (playRequest.ItemIds.Length > 0)
|
if (playRequest.ItemIds.Length > 0)
|
||||||
{
|
{
|
||||||
var itemId = playRequest.ItemIds[0];
|
// Store the full playlist
|
||||||
var streamUrl = BuildStreamUrl(itemId);
|
_playlist = playRequest.ItemIds;
|
||||||
|
_playlistIndex = playRequest.StartIndex ?? 0;
|
||||||
|
|
||||||
|
// Play the item at the start index
|
||||||
|
await PlayItemAtIndexAsync(_playlistIndex, playRequest.StartPositionTicks ?? 0).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task PlayItemAtIndexAsync(int index, long startPositionTicks = 0)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= _playlist.Length)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Invalid playlist index {Index}, playlist has {Count} items", index, _playlist.Length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemId = _playlist[index];
|
||||||
|
_playlistIndex = index;
|
||||||
|
|
||||||
|
// Look up the item first - we need it for file path if using direct mode
|
||||||
|
_currentItem = _libraryManager.GetItemById(itemId);
|
||||||
|
|
||||||
|
// Build stream URL/path with start position
|
||||||
|
var (streamUrl, useDirectPath) = BuildPlaybackUrl(itemId, startPositionTicks);
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Playing item {Index}/{Total} from position {Position}s (direct={Direct}): {Url}",
|
||||||
|
index + 1,
|
||||||
|
_playlist.Length,
|
||||||
|
startPositionTicks / TimeSpan.TicksPerSecond,
|
||||||
|
useDirectPath,
|
||||||
|
streamUrl);
|
||||||
|
|
||||||
_logger.LogInformation("Playing stream URL: {Url}", streamUrl);
|
|
||||||
await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false);
|
await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false);
|
||||||
|
|
||||||
// Track current playback state
|
// Track current playback state
|
||||||
@@ -139,12 +192,168 @@ public class LmsSessionController : ISessionController
|
|||||||
IsPlaying = true;
|
IsPlaying = true;
|
||||||
IsPaused = false;
|
IsPaused = false;
|
||||||
|
|
||||||
// Seek to start position if specified
|
// Track the seek offset so we report the correct position
|
||||||
if (playRequest.StartPositionTicks.HasValue && playRequest.StartPositionTicks.Value > 0)
|
// When using direct file paths, LMS handles seeking natively so no offset needed
|
||||||
{
|
// When using HTTP streaming with startTimeTicks, the stream starts at 0 but we need to report actual position
|
||||||
var positionSeconds = playRequest.StartPositionTicks.Value / TimeSpan.TicksPerSecond;
|
_seekOffsetTicks = useDirectPath ? 0 : startPositionTicks;
|
||||||
await _lmsClient.SeekAsync(_player.MacAddress, positionSeconds).ConfigureAwait(false);
|
|
||||||
|
// Report playback start to Jellyfin
|
||||||
|
await ReportPlaybackStartAsync(itemId, startPositionTicks).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Start progress reporting timer (every 2 seconds)
|
||||||
|
StartProgressTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task ReportPlaybackStartAsync(Guid itemId, long positionTicks)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var startInfo = new PlaybackStartInfo
|
||||||
|
{
|
||||||
|
ItemId = itemId,
|
||||||
|
SessionId = _session.Id,
|
||||||
|
PositionTicks = positionTicks,
|
||||||
|
PlayMethod = PlayMethod.DirectStream,
|
||||||
|
CanSeek = true,
|
||||||
|
IsPaused = false,
|
||||||
|
IsMuted = false
|
||||||
|
};
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Reporting playback start for item {ItemId}, duration: {Duration}",
|
||||||
|
itemId,
|
||||||
|
_currentItem?.RunTimeTicks);
|
||||||
|
await _sessionManager.OnPlaybackStart(startInfo).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to report playback start");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartProgressTimer()
|
||||||
|
{
|
||||||
|
// Stop any existing timer
|
||||||
|
_progressTimer?.Dispose();
|
||||||
|
|
||||||
|
// Report progress every 2 seconds
|
||||||
|
_progressTimer = new Timer(
|
||||||
|
async _ => await ReportPlaybackProgressAsync().ConfigureAwait(false),
|
||||||
|
null,
|
||||||
|
TimeSpan.FromSeconds(2),
|
||||||
|
TimeSpan.FromSeconds(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopProgressTimer()
|
||||||
|
{
|
||||||
|
_progressTimer?.Dispose();
|
||||||
|
_progressTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ReportPlaybackProgressAsync()
|
||||||
|
{
|
||||||
|
if (!IsPlaying || !CurrentItemId.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var status = await _lmsClient.GetPlayerStatusAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
if (status == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LMS reports time relative to the current stream, but after seeking
|
||||||
|
// we're playing a transcoded stream that starts at the seek position.
|
||||||
|
// Add the seek offset to get the actual track position.
|
||||||
|
var positionTicks = (long)(status.Time * TimeSpan.TicksPerSecond) + _seekOffsetTicks;
|
||||||
|
var isPaused = status.Mode == "pause";
|
||||||
|
|
||||||
|
// Update our local state from LMS
|
||||||
|
IsPaused = isPaused;
|
||||||
|
|
||||||
|
// Check if playback has stopped on LMS side (track ended)
|
||||||
|
// Only advance if we're not paused - LMS can briefly report "stop" during transitions
|
||||||
|
if (status.Mode == "stop" && !IsPaused)
|
||||||
|
{
|
||||||
|
// Double-check by getting status again after a brief delay to avoid false positives
|
||||||
|
await Task.Delay(500).ConfigureAwait(false);
|
||||||
|
var confirmStatus = await _lmsClient.GetPlayerStatusAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
if (confirmStatus?.Mode != "stop")
|
||||||
|
{
|
||||||
|
_logger.LogDebug("LMS mode changed from stop, ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("LMS playback stopped, checking if we should advance to next track");
|
||||||
|
|
||||||
|
// Check if there are more tracks in the playlist
|
||||||
|
if (_playlistIndex < _playlist.Length - 1)
|
||||||
|
{
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Track ended, advancing to next track (index {Index}/{Total})",
|
||||||
|
_playlistIndex + 2,
|
||||||
|
_playlist.Length);
|
||||||
|
await PlayItemAtIndexAsync(_playlistIndex + 1).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Playlist finished, reporting playback stopped");
|
||||||
|
await ReportPlaybackStoppedAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var progressInfo = new PlaybackProgressInfo
|
||||||
|
{
|
||||||
|
ItemId = CurrentItemId.Value,
|
||||||
|
SessionId = _session.Id,
|
||||||
|
IsPaused = isPaused,
|
||||||
|
PositionTicks = positionTicks,
|
||||||
|
PlayMethod = PlayMethod.DirectStream,
|
||||||
|
CanSeek = true,
|
||||||
|
IsMuted = status.Volume == 0,
|
||||||
|
VolumeLevel = status.Volume
|
||||||
|
};
|
||||||
|
|
||||||
|
await _sessionManager.OnPlaybackProgress(progressInfo).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogDebug(ex, "Error reporting playback progress");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ReportPlaybackStoppedAsync()
|
||||||
|
{
|
||||||
|
if (!CurrentItemId.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StopProgressTimer();
|
||||||
|
|
||||||
|
var stopInfo = new PlaybackStopInfo
|
||||||
|
{
|
||||||
|
ItemId = CurrentItemId.Value,
|
||||||
|
SessionId = _session.Id
|
||||||
|
};
|
||||||
|
|
||||||
|
_logger.LogInformation("Reporting playback stopped for item {ItemId}", CurrentItemId.Value);
|
||||||
|
await _sessionManager.OnPlaybackStopped(stopInfo).ConfigureAwait(false);
|
||||||
|
|
||||||
|
IsPlaying = false;
|
||||||
|
IsPaused = false;
|
||||||
|
CurrentItemId = null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to report playback stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,9 +376,7 @@ public class LmsSessionController : ISessionController
|
|||||||
case PlaystateCommand.Stop:
|
case PlaystateCommand.Stop:
|
||||||
var stopResult = await _lmsClient.StopAsync(_player.MacAddress).ConfigureAwait(false);
|
var stopResult = await _lmsClient.StopAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
_logger.LogInformation("Stop command result: {Result}", stopResult);
|
_logger.LogInformation("Stop command result: {Result}", stopResult);
|
||||||
IsPlaying = false;
|
await ReportPlaybackStoppedAsync().ConfigureAwait(false);
|
||||||
IsPaused = false;
|
|
||||||
CurrentItemId = null;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PlaystateCommand.Pause:
|
case PlaystateCommand.Pause:
|
||||||
@@ -203,22 +410,87 @@ public class LmsSessionController : ISessionController
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PlaystateCommand.Seek:
|
case PlaystateCommand.Seek:
|
||||||
if (playstateRequest.SeekPositionTicks.HasValue)
|
|
||||||
{
|
|
||||||
var positionSeconds = playstateRequest.SeekPositionTicks.Value / TimeSpan.TicksPerSecond;
|
|
||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
"Seeking player {PlayerName} to {Seconds} seconds",
|
"Seek command received for player {PlayerName}, SeekPositionTicks: {Ticks}, CurrentItemId: {ItemId}, CurrentSeekOffset: {Offset}",
|
||||||
_player.Name,
|
_player.Name,
|
||||||
positionSeconds);
|
playstateRequest.SeekPositionTicks,
|
||||||
|
CurrentItemId,
|
||||||
|
_seekOffsetTicks);
|
||||||
|
if (playstateRequest.SeekPositionTicks.HasValue && CurrentItemId.HasValue)
|
||||||
|
{
|
||||||
|
var positionTicks = playstateRequest.SeekPositionTicks.Value;
|
||||||
|
var positionSeconds = positionTicks / TimeSpan.TicksPerSecond;
|
||||||
|
|
||||||
|
// Check if we're using direct file path mode - if so, LMS can seek natively
|
||||||
|
var config = Plugin.Instance?.Configuration;
|
||||||
|
var canSeekNatively = config?.UseDirectFilePath == true
|
||||||
|
&& !string.IsNullOrEmpty(config.JellyfinMediaPath)
|
||||||
|
&& !string.IsNullOrEmpty(config.LmsMediaPath)
|
||||||
|
&& _currentItem?.Path != null
|
||||||
|
&& _currentItem.Path.StartsWith(config.JellyfinMediaPath, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
if (canSeekNatively)
|
||||||
|
{
|
||||||
|
// Use native LMS seeking - much smoother!
|
||||||
|
_logger.LogInformation("Seeking natively to {Seconds}s using LMS time command", positionSeconds);
|
||||||
await _lmsClient.SeekAsync(_player.MacAddress, positionSeconds).ConfigureAwait(false);
|
await _lmsClient.SeekAsync(_player.MacAddress, positionSeconds).ConfigureAwait(false);
|
||||||
|
// No seek offset needed - LMS handles position tracking natively
|
||||||
|
_seekOffsetTicks = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// For HTTP streams, LMS can't seek directly - we need to restart with startTimeTicks
|
||||||
|
// Build a new URL with the seek position and restart playback
|
||||||
|
var streamUrl = BuildStreamUrlWithPosition(CurrentItemId.Value, positionTicks);
|
||||||
|
_logger.LogInformation(
|
||||||
|
"Seeking by restarting stream at position {Seconds}s: {Url}",
|
||||||
|
positionSeconds,
|
||||||
|
streamUrl);
|
||||||
|
|
||||||
|
await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Track the seek offset so we report the correct position
|
||||||
|
// The transcoded stream starts at 0, but we need to report the actual track position
|
||||||
|
_seekOffsetTicks = positionTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Seek offset is now {Ticks} ticks ({Seconds}s)", _seekOffsetTicks, _seekOffsetTicks / TimeSpan.TicksPerSecond);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Seek command received but SeekPositionTicks or CurrentItemId is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PlaystateCommand.NextTrack:
|
case PlaystateCommand.NextTrack:
|
||||||
|
if (_playlistIndex < _playlist.Length - 1)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Skipping to next track (index {Index})", _playlistIndex + 1);
|
||||||
|
await PlayItemAtIndexAsync(_playlistIndex + 1).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Already at last track, stopping playback");
|
||||||
|
await _lmsClient.StopAsync(_player.MacAddress).ConfigureAwait(false);
|
||||||
|
await ReportPlaybackStoppedAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case PlaystateCommand.PreviousTrack:
|
case PlaystateCommand.PreviousTrack:
|
||||||
// TODO: Implement playlist navigation
|
if (_playlistIndex > 0)
|
||||||
_logger.LogDebug("Track navigation not yet implemented");
|
{
|
||||||
|
_logger.LogInformation("Skipping to previous track (index {Index})", _playlistIndex - 1);
|
||||||
|
await PlayItemAtIndexAsync(_playlistIndex - 1).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// At first track, restart from beginning
|
||||||
|
_logger.LogInformation("At first track, restarting from beginning");
|
||||||
|
await _lmsClient.SeekAsync(_player.MacAddress, 0).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -285,15 +557,85 @@ public class LmsSessionController : ISessionController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the playback URL or file path for the given item.
|
||||||
|
/// Returns a tuple of (url/path, isDirectFilePath).
|
||||||
|
/// </summary>
|
||||||
|
private (string Url, bool IsDirectPath) BuildPlaybackUrl(Guid itemId, long startPositionTicks)
|
||||||
|
{
|
||||||
|
var config = Plugin.Instance?.Configuration;
|
||||||
|
|
||||||
|
// Check if direct file path mode is enabled and configured
|
||||||
|
if (config?.UseDirectFilePath == true
|
||||||
|
&& !string.IsNullOrEmpty(config.JellyfinMediaPath)
|
||||||
|
&& !string.IsNullOrEmpty(config.LmsMediaPath)
|
||||||
|
&& _currentItem?.Path != null)
|
||||||
|
{
|
||||||
|
var directPath = BuildDirectFilePath(_currentItem.Path, config.JellyfinMediaPath, config.LmsMediaPath);
|
||||||
|
if (directPath != null)
|
||||||
|
{
|
||||||
|
_logger.LogDebug(
|
||||||
|
"Using direct file path: {OriginalPath} -> {MappedPath}",
|
||||||
|
_currentItem.Path,
|
||||||
|
directPath);
|
||||||
|
return (directPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogWarning(
|
||||||
|
"Direct file path mode enabled but path mapping failed for: {Path}",
|
||||||
|
_currentItem.Path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to HTTP streaming
|
||||||
|
return (BuildStreamUrlWithPosition(itemId, startPositionTicks), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maps a Jellyfin file path to an LMS file path using the configured path prefixes.
|
||||||
|
/// </summary>
|
||||||
|
private static string? BuildDirectFilePath(string jellyfinPath, string jellyfinPrefix, string lmsPrefix)
|
||||||
|
{
|
||||||
|
// Normalize path separators for comparison
|
||||||
|
var normalizedPath = jellyfinPath.Replace('\\', '/');
|
||||||
|
var normalizedJellyfinPrefix = jellyfinPrefix.TrimEnd('/', '\\').Replace('\\', '/');
|
||||||
|
var normalizedLmsPrefix = lmsPrefix.TrimEnd('/', '\\').Replace('\\', '/');
|
||||||
|
|
||||||
|
if (!normalizedPath.StartsWith(normalizedJellyfinPrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the prefix
|
||||||
|
var relativePath = normalizedPath[normalizedJellyfinPrefix.Length..];
|
||||||
|
return normalizedLmsPrefix + relativePath;
|
||||||
|
}
|
||||||
|
|
||||||
private string BuildStreamUrl(Guid itemId)
|
private string BuildStreamUrl(Guid itemId)
|
||||||
|
{
|
||||||
|
return BuildStreamUrlWithPosition(itemId, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BuildStreamUrlWithPosition(Guid itemId, long startPositionTicks)
|
||||||
{
|
{
|
||||||
var config = Plugin.Instance?.Configuration;
|
var config = Plugin.Instance?.Configuration;
|
||||||
var jellyfinUrl = config?.JellyfinServerUrl?.TrimEnd('/') ?? "http://localhost:8096";
|
var jellyfinUrl = config?.JellyfinServerUrl?.TrimEnd('/') ?? "http://localhost:8096";
|
||||||
var apiKey = config?.JellyfinApiKey ?? string.Empty;
|
var apiKey = config?.JellyfinApiKey ?? string.Empty;
|
||||||
|
|
||||||
// Build audio stream URL that LMS can fetch
|
string url;
|
||||||
// Use direct stream endpoint - simpler and more compatible
|
|
||||||
var url = $"{jellyfinUrl}/Audio/{itemId}/stream?static=true";
|
if (startPositionTicks > 0)
|
||||||
|
{
|
||||||
|
// For seeking, we need to use transcoding (static=true doesn't support startTimeTicks)
|
||||||
|
// Use MP3 transcoding with the start position
|
||||||
|
// Add a cache-busting parameter to ensure we get a fresh stream on each seek
|
||||||
|
var cacheBuster = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||||
|
url = $"{jellyfinUrl}/Audio/{itemId}/stream.mp3?audioCodec=mp3&audioBitRate=320000&startTimeTicks={startPositionTicks}&_={cacheBuster}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// For normal playback from start, use static streaming (better quality, no transcoding)
|
||||||
|
url = $"{jellyfinUrl}/Audio/{itemId}/stream.mp3?static=true";
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(apiKey))
|
if (!string.IsNullOrEmpty(apiKey))
|
||||||
{
|
{
|
||||||
@@ -302,4 +644,30 @@ public class LmsSessionController : ISessionController
|
|||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disposes managed resources.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">Whether to dispose managed resources.</param>
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
StopProgressTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
_disposed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,28 @@ JellyLMS enables Jellyfin to stream audio to LMS, which acts as a multi-room spe
|
|||||||
- **Playback Control**: Play, pause, stop, seek, and volume control forwarded to LMS
|
- **Playback Control**: Play, pause, stop, seek, and volume control forwarded to LMS
|
||||||
- **Stream Bridging**: Generates audio stream URLs from Jellyfin for LMS to consume
|
- **Stream Bridging**: Generates audio stream URLs from Jellyfin for LMS to consume
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|
### Cast to LMS Players
|
||||||
|
Select any LMS player directly from Jellyfin's "Play On" menu:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Plugin Configuration
|
||||||
|
Configure LMS and Jellyfin server connections:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Player Discovery
|
||||||
|
View discovered LMS players with their status and volume levels:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Sync Group Management
|
||||||
|
Create and manage synchronized playback groups for multi-room audio:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- Jellyfin Server 10.10.0 or later
|
- Jellyfin Server 10.10.0 or later
|
||||||
@@ -58,7 +80,7 @@ JellyLMS enables Jellyfin to stream audio to LMS, which acts as a multi-room spe
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Clone the repository
|
# Clone the repository
|
||||||
git clone https://github.com/yourusername/jellyLMS.git
|
git clone https://gitea.tourolle.paris/dtourolle/jellyLMS.git
|
||||||
cd jellyLMS
|
cd jellyLMS
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
@@ -146,6 +168,30 @@ The plugin communicates with LMS using the `slim.request` JSON-RPC method.
|
|||||||
2. Check that audio files are in a format supported by your LMS players
|
2. Check that audio files are in a format supported by your LMS players
|
||||||
3. Ensure players are powered on (plugin can auto-power-on if configured)
|
3. Ensure players are powered on (plugin can auto-power-on if configured)
|
||||||
|
|
||||||
|
## Known Limitations
|
||||||
|
|
||||||
|
### Seeking with HTTP Streaming
|
||||||
|
|
||||||
|
When using HTTP streaming (the default), LMS cannot seek within audio streams. To work around this, when you seek or cast from a specific position, JellyLMS restarts playback with a new transcoded stream that begins at the requested position. This means:
|
||||||
|
|
||||||
|
- **Seeking triggers a brief audio restart** rather than a smooth jump
|
||||||
|
- **Starting playback mid-track** uses transcoding (MP3 320kbps) instead of direct streaming
|
||||||
|
- **Playback from the beginning** uses direct/static streaming for best quality
|
||||||
|
|
||||||
|
This is a fundamental limitation of how LMS handles HTTP streams.
|
||||||
|
|
||||||
|
### Solution: Direct File Access
|
||||||
|
|
||||||
|
If your Jellyfin and LMS servers can both access the same storage (e.g., a NAS), you can enable **Direct File Access** mode in the plugin settings. This allows LMS to read files directly from disk, enabling:
|
||||||
|
|
||||||
|
- **Native smooth seeking** - no audio restart when scrubbing
|
||||||
|
- **Full quality playback** - no transcoding needed
|
||||||
|
- **Better performance** - no HTTP overhead
|
||||||
|
|
||||||
|
To configure, set the path mappings in the plugin settings:
|
||||||
|
- **Jellyfin Media Path**: The path prefix as Jellyfin sees your library (e.g., `/media/music`)
|
||||||
|
- **LMS Media Path**: The same location as LMS sees it (e.g., `/mnt/music` or `//nas/music`)
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Project Structure
|
### Project Structure
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 84 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 127 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
Reference in New Issue
Block a user