Skip to content

Commit c9bcca8

Browse files
committed
returned basic ability of recording screen video
Refactored QuickTime implementation hardly to be more maintainable Added UI button for staring/stopping recording.
1 parent 41e7171 commit c9bcca8

16 files changed

+1418
-1214
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This project gives the opportunity to use your phone even with a broken screen.
2727
- Write messages using PC keyboard
2828
- Support for landscape mode
2929
- Browse your phone files on PC
30+
- Record video of your phone screen while browsing
3031

3132
[Small wiki of project][wiki]
3233

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This project gives the opportunity to use your phone even with a broken screen.
1717
- Write messages using PC keyboard
1818
- Support for landscape mode
1919
- Browse your phone files on PC
20+
- Record video of your phone screen while browsing
2021

2122
[Small wiki of project][wiki]
2223

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<spring.version>4.3.5.RELEASE</spring.version>
1010
<ddmlib.version>25.2.0</ddmlib.version>
1111
<log4j.version>1.2.17</log4j.version>
12+
<guava.version>21.0</guava.version>
1213
<main.class>com.github.xsavikx.androidscreencast.Main</main.class>
1314
<jdk.version>1.8</jdk.version>
1415
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -43,6 +44,11 @@
4344
<artifactId>spring-context</artifactId>
4445
<version>${spring.version}</version>
4546
</dependency>
47+
<dependency>
48+
<groupId>com.google.guava</groupId>
49+
<artifactId>guava</artifactId>
50+
<version>${guava.version}</version>
51+
</dependency>
4652
</dependencies>
4753
<build>
4854
<plugins>
@@ -167,5 +173,6 @@
167173
Write messages using PC keyboard
168174
Support for landscape mode
169175
Browse your phone files on PC
176+
Record video of your phone screen while browsing
170177
</description>
171178
</project>

src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ private RawImage getScreenshot() throws InterruptedException, ClosedByInterruptE
7474
}
7575
currentAdbCommandTimeout = defaultAdbCommandTimeout;
7676
} catch (TimeoutException e) {
77-
LOGGER.warn("Adb command timeout happened. Timeout would be increased by 1 second for the next try.", e);
7877
currentAdbCommandTimeout++;
78+
LOGGER.warn(String.format("Adb command timeout happened. Timeout would be set to %d for the next try.", currentAdbCommandTimeout), e);
7979
} catch (AdbCommandRejectedException e) {
8080
LOGGER.warn("ADB Command was rejected. Will try again in 100 ms.");
8181
Thread.sleep(100);
@@ -99,7 +99,7 @@ private void display(RawImage rawImage) {
9999
SwingUtilities.invokeLater(() -> {
100100
try {
101101
qos.writeFrame(image, FRAME_DURATION);
102-
} catch (IOException e) {
102+
} catch (IORuntimeException e) {
103103
LOGGER.error(e);
104104
}
105105
});
@@ -125,13 +125,9 @@ public void startRecording(File file) {
125125
}
126126

127127
public void stopRecording() {
128-
try {
129-
QuickTimeOutputStream o = qos;
130-
qos = null;
131-
o.close();
132-
} catch (IOException e) {
133-
throw new IORuntimeException(e);
134-
}
128+
QuickTimeOutputStream o = qos;
129+
qos = null;
130+
o.close();
135131
}
136132

137133
public void toggleOrientation() {

src/main/java/com/github/xsavikx/androidscreencast/api/recording/DataAtomOutputStream.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.github.xsavikx.androidscreencast.api.recording;
22

3+
import com.github.xsavikx.androidscreencast.api.recording.atom.AtomType;
4+
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
5+
36
import java.io.FilterOutputStream;
47
import java.io.IOException;
58
import java.io.OutputStream;
@@ -8,6 +11,9 @@
811
import java.util.Date;
912
import java.util.GregorianCalendar;
1013

14+
import static com.google.common.base.Preconditions.checkArgument;
15+
import static com.google.common.base.Preconditions.checkNotNull;
16+
1117
public class DataAtomOutputStream extends FilterOutputStream {
1218

1319
protected static final long MAC_TIMESTAMP_EPOCH = new GregorianCalendar(1904, Calendar.JANUARY, 1).getTimeInMillis();
@@ -279,21 +285,28 @@ public void writeShort(int v) throws IOException {
279285
/**
280286
* Writes an Atom Type identifier (4 bytes).
281287
*
282-
* @param s A string with a length of 4 characters.
288+
* @param type A string with a length of 4 characters.
283289
*/
284-
public void writeType(String s) throws IOException {
285-
if (s.length() != 4) {
286-
throw new IllegalArgumentException("type string must have 4 characters");
287-
}
288-
290+
private void writeType(String type) throws IOException {
291+
checkNotNull(type, "Type string should not be null");
292+
checkArgument(type.length() == 4, "Type string must have exactly 4 characters. type=%s", type);
289293
try {
290-
out.write(s.getBytes("ASCII"), 0, 4);
294+
out.write(type.getBytes("ASCII"), 0, 4);
291295
incCount(4);
292296
} catch (UnsupportedEncodingException e) {
293297
throw new InternalError(e.toString());
294298
}
295299
}
296300

301+
/**
302+
* Writes an Atom Type identifier (4 bytes).
303+
*
304+
* @param atomType AtomType to be written
305+
*/
306+
public void writeType(AtomType atomType) throws IOException {
307+
writeType(atomType.toStringRepresentation());
308+
}
309+
297310
/**
298311
* Writes an unsigned 32 bit integer value.
299312
*
@@ -314,4 +327,13 @@ public void writeUShort(int v) throws IOException {
314327
incCount(2);
315328
}
316329

330+
@Override
331+
public void close() {
332+
try {
333+
flush();
334+
} catch (IOException e) {
335+
throw new IORuntimeException(e);
336+
}
337+
}
338+
317339
}

0 commit comments

Comments
 (0)