Commit b8b5fef4 authored by Thomas Krex's avatar Thomas Krex

recording.settime() funktioniert generell:

	-loop wird unterbochen(adjusting =true)
	-messages sucht alle messages raus
	-pixel[] wird geupdated
	-tonspur wird gesetzt
	-bitmap wird erstellte (graphicsContext.refresh)
	-loop wird wieder gestartet (adjusting=false)
	
ist aber sehr langsam, stürzt  manchmal  ab 
parent fdeb17ec
......@@ -24,19 +24,17 @@ public final class R {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int action_settings=0x7f08000d;
public static final int add=0x7f08000c;
public static final int button_save=0x7f080008;
public static final int feedDetailsLv=0x7f08000a;
public static final int feed_list=0x7f080009;
public static final int action_settings=0x7f08000b;
public static final int add=0x7f08000a;
public static final int button_save=0x7f080006;
public static final int feedDetailsLv=0x7f080008;
public static final int feed_list=0x7f080007;
public static final int feedback_button=0x7f080002;
public static final int play_btn=0x7f080004;
public static final int playerView=0x7f080003;
public static final int progressBar=0x7f08000b;
public static final int stop_btn=0x7f080005;
public static final int progressBar=0x7f080009;
public static final int test_button=0x7f080000;
public static final int tx_name=0x7f080007;
public static final int tx_url=0x7f080006;
public static final int tx_name=0x7f080005;
public static final int tx_url=0x7f080004;
public static final int watch_button=0x7f080001;
}
public static final class layout {
......
......@@ -2,7 +2,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:orientation="horizontal" >
<ImageView
android:id="@+id/playerView"
......@@ -11,24 +11,4 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<Button
android:id="@+id/play_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="25dp"
android:layout_marginLeft="162dp"
android:text="play" />
<Button
android:id="@+id/stop_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/play_btn"
android:layout_alignBottom="@+id/play_btn"
android:layout_marginLeft="76dp"
android:layout_toRightOf="@+id/play_btn"
android:text="stop" />
</RelativeLayout>
\ No newline at end of file
......@@ -4,30 +4,28 @@ import java.io.File;
import java.io.IOException;
import tttclient.services.DownloadService;
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;
import android.widget.Button;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.MediaController.MediaPlayerControl;
import com.example.test.R;
public class PlayerActivity extends Activity {
public class PlayerActivity extends Activity implements MediaPlayerControl {
public String fileName;
public String filePath;
public ImageView imgV;
Bitmap bitmap;
Button playButton;
Button pauseButton;
Recording recording;
MediaPlayer audioPlayer;
private Recording recording;
private MediaPlayer audioPlayer;
private MediaController audioController;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -39,41 +37,134 @@ public class PlayerActivity extends Activity {
File tttFile = new File(filePath + "/" + fileName + ".ttt");
File audioFile = new File(filePath + "/" + fileName + ".mp3");
// create audio player
audioPlayer = MediaPlayer.create(this, Uri.fromFile(audioFile));
try {
playButton = (Button) findViewById(R.id.play_btn);
pauseButton = (Button) findViewById(R.id.stop_btn);
Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth(); // deprecated
int screenHeight = display.getHeight(); // deprecated
recording = new Recording(tttFile, audioPlayer, imgV, screenWidth,
screenWidth);
playButton.setOnClickListener(new OnClickListener() {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@Override
public void onClick(View v) {
recording.play();
// create audio player & control
audioController = new MediaController(this);
audioController.setMediaPlayer(this);
audioController.setAnchorView(imgV);
// final int topContainerId1 = getResources().getIdentifier(
// "mediacontroller_progress", "id", "android");
// final SeekBar seekbar = (SeekBar) audioController
// .findViewById(topContainerId1);
//
// seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
//
// @Override
// public void onStopTrackingTouch(SeekBar seekBar) {
// recording.adjusting = false;
// recording.sliderStateChanged(seekbar.getProgress());
//
// }
//
// @Override
// public void onStartTrackingTouch(SeekBar seekBar) {
// recording.adjusting = true;
//
// }
//
// @Override
// public void onProgressChanged(SeekBar seekBar, int progress,
// boolean fromUser) {
// seekTo(progress);
//
// }
// });
//
}
}
});
@Override
public boolean canPause() {
return true;
}
pauseButton.setOnClickListener(new OnClickListener() {
@Override
public boolean canSeekBackward() {
// TODO Auto-generated method stub
return false;
}
@Override
public void onClick(View v) {
recording.pause();
@Override
public boolean canSeekForward() {
// TODO Auto-generated method stub
return false;
}
}
});
@Override
public int getAudioSessionId() {
return audioPlayer.getAudioSessionId();
}
try {
@Override
public int getBufferPercentage() {
// TODO Auto-generated method stub
return 0;
}
recording = new Recording(tttFile, audioPlayer);
GraphicsContext graphicsContext = new GraphicsContext(imgV,
recording);
@Override
public int getCurrentPosition() {
return audioPlayer.getCurrentPosition();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@Override
public int getDuration() {
return audioPlayer.getDuration();
}
@Override
public boolean isPlaying() {
return audioPlayer.isPlaying();
}
@Override
public void pause() {
if (audioPlayer.isPlaying())
recording.pause();
}
@Override
public void seekTo(int pos) {
recording.sliderStateChanged(pos);
}
@Override
public void start() {
Log.d("MediaController", "start invoked");
if (recording != null)
recording.play();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (audioController != null)
audioController.show();
return false;
}
@Override
protected void onDestroy() {
super.onDestroy();
recording.stop();
recording = null;
audioPlayer.release();
}
}
This diff is collapsed.
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universit?t M?nchen
//
// This file is part of TeleTeachingTool.
//
// TeleTeachingTool 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, either version 3 of the License, or
// (at your option) any later version.
//
// TeleTeachingTool 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 TeleTeachingTool. If not, see <http://www.gnu.org/licenses/>.
/*
* Created on 10.01.2006
*
* Author: Peter Ziewer, TU Munich, Germany - ziewer@in.tum.de
*/
package tttclient.messages;
import java.util.ArrayList;
// non blocking message handling using buffering
public class BufferedMessageConsumer implements MessageConsumer, Runnable {
private MessageConsumer messageConsumer;
private Thread thread;
// creates a non blocking message consumer
// messages are buffered
// message handlimng is done in an own thread
public BufferedMessageConsumer(MessageConsumer consumer) {
messageConsumer = consumer;
start();
}
public void start() {
if (thread == null) {
thread = new Thread(this);
thread.start();
}
}
// message buffer
private ArrayList<Message> messages = new ArrayList<Message>();
// TODO: thing about values and setters
// maximum number of messages to be buffered
public int bufferSize = 1000;
// yield executing thread to allow message consumption
public int yieldSize = 100;
// non blocking message handling
// until buffer is full
public void handleMessage(Message message) {
while (messages.size() > bufferSize)
Thread.yield();
// buffer message
synchronized (messages) {
messages.add(message);
}
// wake thread
synchronized (this) {
notify();
}
// fairness: give chance to consume
if (messages.size() > yieldSize)
Thread.yield();
}
// TODO: only for simulation - remove
private int bandwidth = 1000000;
private int count = 0;
// handle messages in buffer
public void run() {
try {
while (true) {
// handle all messages
while (!messages.isEmpty()) {
Message message;
synchronized (messages) {
message = messages.remove(0);
}
try {
// System.out.println(message);
if (count++ % 1000 == 0)
System.out.print(".");
messageConsumer.handleMessage(message);
} catch (Exception e) {
// TODO: handle or close or whatever
System.out.println("Error while message handling:");
System.out.println(message);
e.printStackTrace();
System.out.println("Trying to continue anyway.");
}
// TODO: remove
// simulate bandwidth limitation
if (!true && message instanceof Message) {
count = ((Message) message).getSize();
try {
int wait = 1000 * count / bandwidth;
if (wait > 100)
System.out.println(count + " bytes - wait " + (wait) + " msec");
Thread.sleep(wait);
} catch (InterruptedException e) {}
}
}
// sleep until receiving new message
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {}
}
}
} catch (Exception e) {
// TODO: handle or close or whatever
System.out.println("player crashed");
e.printStackTrace();
}
}
}
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universit?t M?nchen
//
// This file is part of TeleTeachingTool.
//
// TeleTeachingTool 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, either version 3 of the License, or
// (at your option) any later version.
//
// TeleTeachingTool 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 TeleTeachingTool. If not, see <http://www.gnu.org/licenses/>.
/*
* Created on 12.12.2005
*
* Author: Peter Ziewer, TU Munich, Germany - ziewer@in.tum.de
*/
package tttclient.messages;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import tttclient.ttt.Constants;
import tttclient.ttt.GraphicsContext;
public class CopyRectMessage extends FramebufferUpdateMessage {
protected int sourceX;
protected int sourceY;
public CopyRectMessage(int timestamp, int destinationX, int destinationY,
int width, int height, GraphicsContext graphicsContext,
DataInputStream in) throws IOException {
this(timestamp, destinationX, destinationY, width, height, in
.readUnsignedShort(), in.readUnsignedShort());
paint(graphicsContext);
}
public CopyRectMessage(int timestamp, int destinationX, int destinationY,
int width, int height, int sourceX, int sourceY) {
super(timestamp, destinationX, destinationY, width, height);
this.sourceX = sourceX;
this.sourceY = sourceY;
}
@Override
public int getEncoding() {
return Constants.EncodingCopyRect;
}
@Override
public void paint(GraphicsContext graphicsContext) {
// TODO impelement copyArea
// graphicsContext.memGraphics.copyArea(sourceX, sourceY, width, height,
// x
// - sourceX, y - sourceY);
graphicsContext.handleUpdatedPixels(x, y, width, height);
}
@Override
public String toString() {
return super.toString() + " from (" + sourceX + "," + sourceY + ")";
}
/*******************************************************************************************************************
* write message
******************************************************************************************************************/
// write message to TTT output stream
@Override
public void write(DataOutputStream out, int writeTimestamp)
throws IOException {
// header
writeHeader(out, writeTimestamp);
out.writeShort(x);
out.writeShort(y);
out.writeShort(width);
out.writeShort(height);
};
// return size of message in bytes (if written to stream)
@Override
public int getSize() {
return 9;
}
}
......@@ -29,6 +29,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import tttclient.ttt.Constants;
import android.graphics.Rect;
public abstract class FramebufferUpdateMessage extends Message {
protected int x;
......@@ -54,9 +55,9 @@ public abstract class FramebufferUpdateMessage extends Message {
return width * height;
}
// public Rectangle getBounds() {
// return new Rectangle(x, y, width, height);
// }
public Rect getBounds() {
return new Rect(x, y, x + width, y + height);
}
@Override
public String toString() {
......
......@@ -34,7 +34,6 @@ import java.util.Random;
import tttclient.ttt.Constants;
import tttclient.ttt.GraphicsContext;
import android.util.Log;
public class HextileMessage extends FramebufferUpdateMessage {
// reading from stream is easier then reading from byte array
......@@ -61,7 +60,6 @@ public class HextileMessage extends FramebufferUpdateMessage {
this(timestamp, in.readShort(), in.readShort(), in.readShort(), in
.readShort(), FramebufferUpdateMessage.readBytes(in, size - 8));
Log.d("HextileMessage", " timestamp: " + timestamp);
}
// constructor - reading message from RFB input stream and directly draw
......@@ -89,9 +87,10 @@ public class HextileMessage extends FramebufferUpdateMessage {
try {
byteArrayInputStream.reset();
// fill the pixel array
handleHextileRect(graphicsContext, is, null, x, y, width, height,
updateFlag);
// change pixels of bitmap
graphicsContext.handleUpdatedPixels(x, y, width, height);
} catch (IOException e) {
......
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universit?t M?nchen
//
// This file is part of TeleTeachingTool.
//
// TeleTeachingTool 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, either version 3 of the License, or
// (at your option) any later version.
//
// TeleTeachingTool 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 TeleTeachingTool. If not, see <http://www.gnu.org/licenses/>.
/*
* Created on 11.01.2006
*
* Author: Peter Ziewer, TU Munich, Germany - ziewer@in.tum.de
*/
package tttclient.messages;
import java.io.IOException;
import java.io.OutputStream;
import tttclient.ttt.Constants;
public class KeyEventMessage extends UserInputMessage {
private final byte[] buffer = new byte[8];
public KeyEventMessage(int keysym, boolean down) {
buffer[0] = (byte) Constants.KeyboardEvent;
buffer[1] = (byte) (down ? 1 : 0);
buffer[2] = (byte) 0;
buffer[3] = (byte) 0;
buffer[4] = (byte) ((keysym >> 24) & 0xff);
buffer[5] = (byte) ((keysym >> 16) & 0xff);
buffer[6] = (byte) ((keysym >> 8) & 0xff);
buffer[7] = (byte) (keysym & 0xff);
}
public void writeRFB(OutputStream out) throws IOException {
out.write(buffer);
}
}
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universit?t M?nchen
//
// This file is part of TeleTeachingTool.
//
// TeleTeachingTool 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, either version 3 of the License, or
// (at your option) any later version.
//
// TeleTeachingTool 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 TeleTeachingTool. If not, see <http://www.gnu.org/licenses/>.
/*
* Created on 13.01.2006
*
* Author: Peter Ziewer, TU Munich, Germany - ziewer@in.tum.de
*/
package tttclient.messages;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import tttclient.ttt.Constants;
import tttclient.ttt.GraphicsContext;
import android.graphics.Paint;
public class LineAnnotation extends SimpleAnnotation {
public LineAnnotation(int timestamp, int color, int startx, int starty,
int endx, int endy) {
super(timestamp, color, startx, starty, endx, endy);
}
public LineAnnotation(int timestamp, DataInputStream in) throws IOException {
this(timestamp, in.readUnsignedByte(), in.readUnsignedShort(), in
.readUnsignedShort(), in.readUnsignedShort(), in
.readUnsignedShort());
}
// MODMSG
/**
* create LineAnnotation of corresponding XML-Element (used by messaging)
*/
public LineAnnotation(org.w3c.dom.Element xmlNode) {
super(xmlNode);
}
@Override
public int getEncoding() {
return Constants.AnnotationLine;
}
@Override
void computeShape() {
// shape = new BasicStroke(2.5f, BasicStroke.CAP_ROUND,
// BasicStroke.JOIN_ROUND).createStrokedShape(new Line2D.Double(
// startx, starty, endx, endy));
// thumbshape = new BasicStroke(6f, BasicStroke.CAP_ROUND,
// BasicStroke.JOIN_ROUND).createStrokedShape(new Line2D.Double(
// startx, starty, endx, endy));
}
// public void paintToThumbnail(Graphics2D graphics) {
// // TODO: fix color - don't use table for new protocol
// graphics.setColor(annotationColors[color]);
// graphics.fill(thumbshape);
// }
@Override
public void paint(GraphicsContext graphicsContext) {
// TODO: fix color - don't use table for new protocol
// replace BasicStroke, no caps available
Paint paint = new Paint(annotationColors[color]);
paint.setStrokeWidth(2.5f);
graphicsContext.getCanvas().drawLine(startx, starty, endx, endy, paint);