This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
/
ChapterFileTranscodeVirtualFolder.java
80 lines (72 loc) · 3.06 KB
/
ChapterFileTranscodeVirtualFolder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* PS3 Media Server, for streaming any medias to your PS3.
* Copyright (C) 2008 A.Brochard
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.pms.dlna;
import net.pms.dlna.virtual.VirtualFolder;
/**
* The ChapterFileTranscodeVirtualFolder is a {@link DLNAResource} container that
* examines the media to be transcoded and creates several virtual children. This
* is done by taking the full length of the media and creating virtual chapters
* by means of a specified interval length. These virtual chapters are presented
* to the user in the "#Transcode#" folder when the option "Chapter #Transcode#
* folder support" is activated in the settings.
*/
public class ChapterFileTranscodeVirtualFolder extends VirtualFolder {
private boolean resolved;
private int interval;
/**
* Constructor for a {@link ChapterFileTranscodeVirtualFolder}. The constructor
* does not create the children for this instance, it only sets the name, the
* icon for a thumbnail and the interval at which chapter markers must be placed
* when the children are created by {@link #resolve()}.
* @param name The name of this instance.
* @param thumbnailIcon The thumbnail for this instance.
* @param interval The interval (in minutes) at which a chapter marker will be
* placed.
*/
public ChapterFileTranscodeVirtualFolder(String name, String thumbnailIcon, int interval) {
super(name, thumbnailIcon);
this.interval = interval;
}
/* (non-Javadoc)
* @see net.pms.dlna.DLNAResource#resolve()
*/
@Override
public void resolve() {
super.resolve();
if (!resolved && getChildren().size() == 1) { //OK
DLNAResource child = getChildren().get(0);
child.resolve();
int nbMinutes = (int) (child.getMedia().getDurationInSeconds() / 60);
int nbIntervals = nbMinutes / interval;
for (int i = 1; i <= nbIntervals; i++) {
// TODO: Remove clone(), instead create a new object from scratch to avoid unwanted cross references.
DLNAResource newChildNoSub = (DLNAResource) child.clone();
newChildNoSub.setId(null);
newChildNoSub.setPlayer(child.getPlayer());
newChildNoSub.setMedia(child.getMedia());
newChildNoSub.setNoName(true);
newChildNoSub.setMediaAudio(child.getMediaAudio());
newChildNoSub.setMediaSubtitle(child.getMediaSubtitle());
newChildNoSub.setSplitRange(new Range.Time(60.0 * i * interval, newChildNoSub.getMedia().getDurationInSeconds()));
addChildInternal(newChildNoSub);
}
}
resolved = true;
}
}