Commit dc196368 authored by Thomas Krex's avatar Thomas Krex

added mediaplayer for audio playback

parent 8d0f3273
......@@ -8,6 +8,8 @@ import tttclient.ttt.GraphicsContext;
import tttclient.ttt.Recording;
import android.app.Activity;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
......@@ -25,6 +27,7 @@ public class PlayerActivity extends Activity {
Button playButton;
Button pauseButton;
Recording recording;
MediaPlayer audioPlayer;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -34,7 +37,12 @@ public class PlayerActivity extends Activity {
fileName = getIntent().getStringExtra(DownloadService.FILE_NAME);
filePath = getIntent().getStringExtra(DownloadService.FILE_PATH);
File file = new File(filePath + "/" + fileName + ".ttt");
File tttFile = new File(filePath + "/" + fileName + ".ttt");
File audioFile = new File(filePath + "/" + fileName + ".mp3");
// create audio player
audioPlayer = MediaPlayer.create(this, Uri.fromFile(audioFile));
playButton = (Button) findViewById(R.id.play_btn);
pauseButton = (Button) findViewById(R.id.stop_btn);
......@@ -58,7 +66,7 @@ public class PlayerActivity extends Activity {
try {
recording = new Recording(file);
recording = new Recording(tttFile, audioPlayer);
GraphicsContext graphicsContext = new GraphicsContext(imgV,
recording);
......
......@@ -166,7 +166,7 @@ public class HextileMessage extends FramebufferUpdateMessage {
// TODO: what if bytesPerPixel of message differ from
// graphicsContext???????????
// Read and draw the background if specified.
byte[] cbuf = new byte[graphicsContext.prefs.bytesPerPixel];
byte[] cbuf = new byte[graphicsContext.getPrefs().bytesPerPixel];
if ((subencoding & Constants.HextileBackgroundSpecified) != 0) {
is.readFully(cbuf);
......@@ -180,7 +180,7 @@ public class HextileMessage extends FramebufferUpdateMessage {
}
fillRect(graphicsContext, tx, ty, tw, th,
graphicsContext.hextile_bg_encoded, updateFlag);
graphicsContext.getHextile_bg_encoded(), updateFlag);
// Read the foreground color if specified.
if ((subencoding & Constants.HextileForegroundSpecified) != 0) {
......@@ -202,7 +202,7 @@ public class HextileMessage extends FramebufferUpdateMessage {
int bufsize = nSubrects * 2;
if ((subencoding & Constants.HextileSubrectsColoured) != 0) {
bufsize += nSubrects * graphicsContext.prefs.bytesPerPixel;
bufsize += nSubrects * graphicsContext.getPrefs().bytesPerPixel;
}
byte[] buf = new byte[bufsize];
is.readFully(buf);
......@@ -221,7 +221,7 @@ public class HextileMessage extends FramebufferUpdateMessage {
// store encoded foreground color
graphicsContext.setForeground(buf, i);
i += graphicsContext.prefs.bytesPerPixel;
i += graphicsContext.getPrefs().bytesPerPixel;
}
// decode subrect
b1 = buf[i++] & 0xFF;
......@@ -232,7 +232,7 @@ public class HextileMessage extends FramebufferUpdateMessage {
sh = (b2 & 0xf) + 1;
fillRect(graphicsContext, sx, sy, sw, sh,
graphicsContext.hextile_fg_encoded, updateFlag);
graphicsContext.getHextile_fg_encoded(), updateFlag);
}
}
......@@ -243,7 +243,7 @@ public class HextileMessage extends FramebufferUpdateMessage {
Log.d("HextileMessage", "handle RawRect at " + x + " , " + y + " , "
+ w + " , " + h);
switch (graphicsContext.prefs.bytesPerPixel) {
switch (graphicsContext.getPrefs().bytesPerPixel) {
// case 1:
// for (int dy = y; dy < y + h; dy++) {
// is.readFully(graphicsContext.pixels8, dy
......@@ -265,14 +265,15 @@ public class HextileMessage extends FramebufferUpdateMessage {
if (os != null)
os.write(buf);
int offset = dy * graphicsContext.prefs.framebufferWidth + x;
if (graphicsContext.prefs.bigEndian)
int offset = dy * graphicsContext.getPrefs().framebufferWidth
+ x;
if (graphicsContext.getPrefs().bigEndian)
for (int i = 0; i < w; i++)
graphicsContext.pixels[offset + i] = (buf[i * 2] & 0xFF) << 8
graphicsContext.getPixels()[offset + i] = (buf[i * 2] & 0xFF) << 8
| (buf[i * 2 + 1] & 0xFF);
else
for (int i = 0; i < w; i++)
graphicsContext.pixels[offset + i] = (buf[i * 2 + 1] & 0xFF) << 8
graphicsContext.getPixels()[offset + i] = (buf[i * 2 + 1] & 0xFF) << 8
| (buf[i * 2] & 0xFF);
}
......@@ -287,15 +288,16 @@ public class HextileMessage extends FramebufferUpdateMessage {
if (os != null)
os.write(buf);
int offset = dy * graphicsContext.prefs.framebufferWidth + x;
if (graphicsContext.prefs.bigEndian)
int offset = dy * graphicsContext.getPrefs().framebufferWidth
+ x;
if (graphicsContext.getPrefs().bigEndian)
for (int i = 0; i < w; i++)
graphicsContext.pixels[offset + i] = (buf[i * 4 + 1] & 0xFF) << 16
graphicsContext.getPixels()[offset + i] = (buf[i * 4 + 1] & 0xFF) << 16
| (buf[i * 4 + 2] & 0xFF) << 8
| (buf[i * 4 + 3] & 0xFF);
else
for (int i = 0; i < w; i++)
graphicsContext.pixels[offset + i] = (buf[i * 4 + 2] & 0xFF) << 16
graphicsContext.getPixels()[offset + i] = (buf[i * 4 + 2] & 0xFF) << 16
| (buf[i * 4 + 1] & 0xFF) << 8
| (buf[i * 4] & 0xFF);
}
......@@ -324,10 +326,10 @@ public class HextileMessage extends FramebufferUpdateMessage {
// graphicsContext.updateView();
for (int i = y; i < y + h; i++) {
int offset = i * graphicsContext.prefs.framebufferWidth + x;
int offset = i * graphicsContext.getPrefs().framebufferWidth + x;
for (int j = 0; j < w; j++) {
// TODO: add 8bit support
graphicsContext.pixels[offset + j] = color;
graphicsContext.getPixels()[offset + j] = color;
}
}
graphicsContext.handleUpdatedPixels(x, y, w, h);
......
......@@ -92,7 +92,7 @@ public class Messages {
while (true) {
// TODO: show progress
Message message = Message.readMessage(in, recording.prefs);
Message message = Message.readMessage(in, recording.prefs());
if (message == null)
continue;
......@@ -228,14 +228,15 @@ public class Messages {
synchronized public void setTime_full_frame_check(int time) {
// long t = System.currentTimeMillis();
boolean[][] covered = new boolean[recording.prefs.framebufferWidth][recording.prefs.framebufferHeight];
boolean[][] covered = new boolean[recording.prefs().framebufferWidth][recording
.prefs().framebufferHeight];
int coveredCounter = 0;
// if not set newly, this causes a call of stop() in run() beacuse end
// of recording reached
int newNext = messages.size();
int full = recording.prefs.framebufferWidth
* recording.prefs.framebufferHeight;
int full = recording.prefs().framebufferWidth
* recording.prefs().framebufferHeight;
int totalCounter = 0;
......@@ -390,7 +391,7 @@ public class Messages {
// now paint collected messages (keyframe)
for (int i = 0; i < collected.size(); i++) {
// System.out.println(collected.get(i));
collected.get(i).paint(recording.graphicsContext);
collected.get(i).paint(recording.graphicsContext());
}
// set next message for run loop
......@@ -538,7 +539,7 @@ public class Messages {
// now paint collected messages (keyframe)
for (int i = 0; i < collected.size(); i++) {
// System.out.println(collected.get(i));
collected.get(i).paint(recording.graphicsContext);
collected.get(i).paint(recording.graphicsContext());
}
// set next message for run loop
......
......@@ -113,7 +113,7 @@ public class RawMessage extends FramebufferUpdateMessage {
Log.d("RawMessage", "handleRaw Rect: " + x + " , " + y + " , " + w
+ " , " + h);
switch (graphicsContext.prefs.bytesPerPixel) {
switch (graphicsContext.getPrefs().bytesPerPixel) {
// case 1:
// for (int dy = y; dy < y + h; dy++) {
// is.readFully(graphicsContext.pixels8, dy
......@@ -135,14 +135,15 @@ public class RawMessage extends FramebufferUpdateMessage {
if (os != null)
os.write(buf);
int offset = dy * graphicsContext.prefs.framebufferWidth + x;
if (graphicsContext.prefs.bigEndian)
int offset = dy * graphicsContext.getPrefs().framebufferWidth
+ x;
if (graphicsContext.getPrefs().bigEndian)
for (int i = 0; i < w; i++)
graphicsContext.pixels[offset + i] = (buf[i * 2] & 0xFF) << 8
graphicsContext.getPixels()[offset + i] = (buf[i * 2] & 0xFF) << 8
| (buf[i * 2 + 1] & 0xFF);
else
for (int i = 0; i < w; i++)
graphicsContext.pixels[offset + i] = (buf[i * 2 + 1] & 0xFF) << 8
graphicsContext.getPixels()[offset + i] = (buf[i * 2 + 1] & 0xFF) << 8
| (buf[i * 2] & 0xFF);
}
......@@ -157,15 +158,16 @@ public class RawMessage extends FramebufferUpdateMessage {
if (os != null)
os.write(buf);
int offset = dy * graphicsContext.prefs.framebufferWidth + x;
if (graphicsContext.prefs.bigEndian)
int offset = dy * graphicsContext.getPrefs().framebufferWidth
+ x;
if (graphicsContext.getPrefs().bigEndian)
for (int i = 0; i < w; i++)
graphicsContext.pixels[offset + i] = (buf[i * 4 + 1] & 0xFF) << 16
graphicsContext.getPixels()[offset + i] = (buf[i * 4 + 1] & 0xFF) << 16
| (buf[i * 4 + 2] & 0xFF) << 8
| (buf[i * 4 + 3] & 0xFF);
else
for (int i = 0; i < w; i++)
graphicsContext.pixels[offset + i] = (buf[i * 4 + 2] & 0xFF) << 16
graphicsContext.getPixels()[offset + i] = (buf[i * 4 + 2] & 0xFF) << 16
| (buf[i * 4 + 1] & 0xFF) << 8
| (buf[i * 4] & 0xFF);
}
......
......@@ -16,20 +16,20 @@ import android.widget.ImageView;
@SuppressLint("NewApi")
public class GraphicsContext implements MessageConsumer {
public Handler handler;
public Canvas canvas;
public Canvas scaledCanvas;
public BitmapContainer bitmapContainer;
public Bitmap scaledBitmap;
public ImageView imgView;
private final Handler handler;
private final Canvas canvas;
private Canvas scaledCanvas;
private final BitmapContainer bitmapContainer;
private Bitmap scaledBitmap;
private final ImageView imgView;
boolean refreshEnabled;
public MessageProducer producer;
public ProtocolPreferences prefs;
public int screenWidth = 1280;
public int screenHeight = 768;
public byte[] hextile_bg_encoded;
public byte[] hextile_fg_encoded;
public int[] pixels;
private final MessageProducer producer;
private final ProtocolPreferences prefs;
private final int screenWidth = 1280;
private final int screenHeight = 768;
private final byte[] hextile_bg_encoded;
private final byte[] hextile_fg_encoded;
private final int[] pixels;
public GraphicsContext(ImageView imgV, Recording record) {
this.imgView = imgV;
......@@ -69,6 +69,22 @@ public class GraphicsContext implements MessageConsumer {
};
}
public int[] getPixels() {
return this.pixels;
}
public ProtocolPreferences getPrefs() {
return this.prefs;
}
public byte[] getHextile_bg_encoded() {
return hextile_bg_encoded;
}
public byte[] getHextile_fg_encoded() {
return hextile_fg_encoded;
}
private final Runnable updateViewTask = new Runnable() {
@Override
......
......@@ -38,23 +38,31 @@ import java.util.zip.InflaterInputStream;
import tttclient.messages.Message;
import tttclient.messages.MessageProducerAdapter;
import tttclient.messages.Messages;
import android.media.MediaPlayer;
import android.util.Log;
public class Recording extends MessageProducerAdapter implements Runnable {
// TODO: visibility
public ProtocolPreferences prefs = new ProtocolPreferences();
public GraphicsContext graphicsContext;
private final ProtocolPreferences prefs;
private GraphicsContext graphicsContext;
public Messages messages = new Messages(this);
private final Messages messages;
// public AudioVideoPlayer audioVideoPlayer;
public File tttFile;
private File tttFile;
private final MediaPlayer audioPlayer;
public Messages getMessages() {
return messages;
}
public ProtocolPreferences prefs() {
return this.prefs;
}
public GraphicsContext graphicsContext() {
return this.graphicsContext;
}
public void setfileDesktop(File name) {
tttFile = name;
}
......@@ -63,8 +71,11 @@ public class Recording extends MessageProducerAdapter implements Runnable {
messages.setmessages(list);
}
public Recording(File file) throws IOException {
public Recording(File file, MediaPlayer audioPlayer) throws IOException {
// read
messages = new Messages(this);
prefs = new ProtocolPreferences();
this.audioPlayer = audioPlayer;
read(file);
// Note: keyframes are computed dynamically during random access
......@@ -110,10 +121,6 @@ public class Recording extends MessageProducerAdapter implements Runnable {
// }
}
public GraphicsContext getGraphicsContext() {
return graphicsContext;
}
public String getFileName() throws IOException {
return tttFile.getCanonicalPath();
}
......@@ -529,8 +536,8 @@ public class Recording extends MessageProducerAdapter implements Runnable {
}
// fireTimeChangedEvent(TimeChangedListener.PLAY);
paused = false;
// if (audioVideoPlayer != null)
// audioVideoPlayer.play();
if (audioPlayer != null)
audioPlayer.start();
interrupt();
}
......@@ -539,9 +546,9 @@ public class Recording extends MessageProducerAdapter implements Runnable {
synchronized public void pause() {
// fireTimeChangedEvent(TimeChangedListener.PAUSE);
paused = true;
// if (audioVideoPlayer != null)
// audioVideoPlayer.pause();
// interrupt();
if (audioPlayer != null)
audioPlayer.pause();
interrupt();
}
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment