domingo, 2 de marzo de 2014

How to configure AppleTV 3th Generation for play content of Plex Media Server without Jailbreak!

1) Download Plex Media Server
https://plex.tv/downloads

2) Download PlexConnect

https://github.com/iBaa/PlexConnect

3) Create the cert (Run in terminal)

For create "trailers.pem" and "trailers.key" files:
openssl req -new -nodes -newkey rsa:2048 -out ~/Desktop/trailers.pem -keyout ~/Desktop/trailers.key -x509 -days 7300 -subj "/C=US/CN=trailers.apple.com"

For create "trailers.cer" file:
openssl x509 -in ~/Desktop/trailers.pem -outform der -out ~/Desktop/trailers.cer && cat ~/Desktop/trailers.key >> ~/Desktop/trailers.pem


4) Move 3 new files to certificates directory

5) Create AppleScript app with follow code:

tell application "Terminal"
 activate
 do script "cd ruta-hacia-PlexConnect" in front window
 delay 1 -- pause for a second 
 do script "sudo ./PlexConnect.py" in front window
 delay 1 -- pause for a second
 do script "password" in front window
end tell

6) Use Apple Configurator to install  .cer into AppleTV

7) Modify Settings.py file to change this values:

   a) router IP
   b) complete path to trailers.pam file

8) Configure DSN address in AppleTV, putting IP address of computer which run Plex Media Server

9) In the computer which run Plex Media Server, run the AppleTV3.app in background.

Note: You can change the DNS address for Default Address if you whish.

martes, 20 de septiembre de 2011

martes, 24 de mayo de 2011

[Java] Move dinamically images using threads in Java Applet



This sample show how to move dinamically images in some applet scene, using doble buffer technique and using threas to move one image in a specific direction.

package mx.gcross.samples;

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;

/**
*
* @author René Cruz - G-Cross Studio 2011
*/

public class MoveImage extends Applet {

private Image dobleBuffer;
private Graphics myGraphics;
private Image background;
private Image nave;
int cordX;
int cordY;

@Override
public void init() {
background = getImage(getDocumentBase(), "background.jpg");
nave = getImage(getDocumentBase(), "nave.png");

// Init first coordinates
cordX = (int) (Math.random() * getWidth());
cordY = getHeight();

// Init doble buffer
dobleBuffer = createImage(getWidth(), getHeight());
myGraphics = dobleBuffer.getGraphics();

//Draw images, only the first time
drawImages();
animateShip();
}

@Override
public void update(Graphics g) {
//Draw images in the new positions
drawImages();
//Draw the buffer in the screen
g.drawImage(dobleBuffer, 0, 0, this);
}

public void animateShip() {

Thread hilo = new Thread() {
@Override
public void run() {
try {
super.run();
while (true) {
// change position of Y, and validate if need calculate new coordinates of ship...
cordY--;
if (cordY < -30) {
cordX = (int) (Math.random() * getWidth());
cordY = getHeight();
}
repaint();
// make a pause for 10 milliseconds
sleep(10);
}

} catch (InterruptedException ex) {
// do something...
}
}
};
hilo.start();
}

public void drawImages() {
myGraphics.drawImage(background, 0, 0, getWidth(), getHeight(), this);
myGraphics.drawImage(nave, cordX, cordY, this);
}
}
Test the code and comment, thanks!.

If you prefer the complete code source, resources and the HTML document in a Netbeans project, Download It Here!

lunes, 11 de abril de 2011

[Java] Connect PC and Mobile Phone over Bluetooth using CA-Mobile API


This example shows how use CA-Mobile API to connect PC and Mobile Phones over Bluetooth connections. In this case, I show you how to implement a Server Bluetooth in a PC and we will use a mobile app for chat between peer (PC or Phone).

Using the CA-Mobile Framework you can implements collaborative applications in a simple way, because the API simplifies the hard work to control bluetooth communications.

The CA-Mobile API use bluecove bluetooth library for SE version, and you need add both libraries in your proyects: CA-Mobile Framework API and bluecove 2.1.X.

See the library package in the image:

Well, the first code is an Server Control class (MyBTServer.java). The code Here:

package mx.camobile.bluetooth;

import emo.comm.connector.bluetooth.server.BTMultiServer;
import emo.comm.message.common.IMsgProcessor;
import emo.comm.message.common.Message;
import emo.comm.message.common.chat.ChatRoster;

/**
*
* @author René Cruz - G-Cross Studio 2011
*/
public class MyBTServer {
//Bluetooth Server Object

private final BTMultiServer btServer;

public MyBTServer(String nickName, IMsgProcessor processor) {
/* Create an instance of Bluetooth MultiServer
Parameters:
1) The UUID (0x11111) for the published bluetooth service (it will be the same in the mobile app)
2) One MsgProcessor (in this case, the same class process all incomming messages)
3) One Roster instance, the Mobile API includes a simple ChatRoster class.
4) The mode of messages propagation, in this case the sender of messages
* is excludes of propagation to avoid repeated messages.
5) Optional, the name of this server. If not specifies a nickname, the bluetooth
* device ID will be used like nickName.
*/
btServer = new BTMultiServer(0x11111, processor, new ChatRoster(),
BTMultiServer.EXCLUDE_SENDER_BROADCAST, nickName);
}

public void startServer() {
//Start Bluetooth Server
btServer.startServer();
}

public void sendMessage(Message msg) {
//Send one message to all connected peers.
btServer.sendMessage(msg);
}
}

The follow code is for create a GUI for the Chat Server, however I only comment the lines related with the Bluetooth Server. Here is the code for GUI of Bluetooth Server and Chat:
package mx.camobile.gui;

import emo.comm.message.common.IMsgProcessor;
import emo.comm.message.common.Message;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import mx.camobile.bluetooth.MyBTServer;

/**
*
* @author René Cruz - G-Cross Studio 2011
*/
public class SimpleGUI extends JFrame implements ActionListener, IMsgProcessor {

private JTextField txtNickName;
private JTextField txtMessage;
private JButton btnConnect;
private JButton btnSend;
private JTextPane txtHistory;
private JScrollPane panel;
private JPanel panelNorth;
private JPanel panelSouth;
private MyBTServer btServer;

public SimpleGUI() {
setSize(400, 200);
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

panelNorth = new JPanel();
panelNorth.add(new JLabel("Nickname:"));
txtNickName = new JTextField(20);
panelNorth.add(txtNickName);
btnConnect = new JButton("Connect");
btnConnect.addActionListener(this);
panelNorth.add(btnConnect);
add(panelNorth, BorderLayout.NORTH);

txtHistory = new JTextPane();
panel = new JScrollPane();
panel.setViewportView(txtHistory);
add(panel, BorderLayout.CENTER);

panelSouth = new JPanel();
panelSouth.add(new JLabel("Message:"));
txtMessage = new JTextField(20);
panelSouth.add(txtMessage);
btnSend = new JButton("Send");
btnSend.addActionListener(this);
panelSouth.add(btnSend);
add(panelSouth, BorderLayout.SOUTH);
setVisible(true);
}

public static void main(String[] args) {
SimpleGUI simpleGUI = new SimpleGUI();
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnConnect) {
//Create a instance of BTServer controller
btServer = new MyBTServer(txtNickName.getText(), this);
//Start BTServer
btServer.startServer();
btnConnect.setEnabled(false);
txtHistory.setText("Server started\n");
} else if (e.getSource() == btnSend) {
/*
* Create an instance of Message class, to send it over BluetoothServer
* Parameters:
* 1) Type of message (LOGIN_MESSAGE, LOGOUT_MESSAGE, NORMAL_MESSAGE, ROSTER_MESSATE, SYSTEM_MESSAGE)
* 2) NickName of sender
* 3) Body or content of Message
*/
Message message = new Message(Message.NORMAL_MESSAGE, txtNickName.getText(), txtMessage.getText());
//Send message over bluetooth server
btServer.sendMessage(message);
txtMessage.setText("");
}
}

public void processMsg(String string) {
// not used in this example...
}

public void processMsg(Message msg) {
// Extract the Type of Message
switch (msg.getType()) {
case Message.LOGIN_MESSAGE: {
txtHistory.setText(txtHistory.getText() + msg.getSender() + " is connected\n");
}
break;
case Message.LOGOUT_MESSAGE: {
txtHistory.setText(txtHistory.getText() + msg.getSender() + " was disconnected\n");
}
break;
case Message.NORMAL_MESSAGE: {
txtHistory.setText(txtHistory.getText() + msg.getSender() + ": " + msg.getMsgBody() + "\n");
}
break;
}
}

public void processMsg(int i) {
// not used in this example...
}
}

For test this Bluetooth Server, I used a mobile appication that was developed using CA-Mobile API ME version, however I will show you the code in the next examples. The mobile chat application was tested using a Sony Ericsson K790 mobile phone, and works great!

The libraries used in this example:

Download CA-Mobile API ME version beta 1.3
Download CA-Mobile API SE version beta 1.0
Download Bluecove Bluetooth Library 2.1 (x86)
Download Bluecove Bluetooth Library 2.1.1 (x64)

Test the code and comment, thanks!.

Download the Netbeans project and mobile application J2ME for testing(.jar/.jad) Here!

sábado, 9 de abril de 2011

[J2ME] CA-Mobile Framework


Well, in this occasion want to show you the CA-Mobile Framework, a tool for design & develop educational collaborative activities based on mobile devices with J2ME support.

CA-Mobile Framework was developed when I was studying my Ph.D., and includes several instruments for the educational field, however this framework includes an API (CA-Mobile API) for develop collaborative software over Bluetooth communications between mobile devices and PC. For this reason, the CA-Mobile API include two versions: mobile version and desktop version.

Using this API you can develop applications in mobile devices in an easy way, including a simple and homogeneous GUI based on single menus and canvas to show different content (text, graphics, animations, etc).

The CA-Mobile API allows you to communicate mobile devices and PC on the same way to exchange string messages and files like images from camera, text, video or http://www.blogger.com/img/blank.gifanother format.

This is a work in progress but the beta version of two API are available for use it in open and non-comercial projects.

This is the official site of CA-Mobile Framework and you can download beta version of API there.

If you need some help or you are interested in this project, you can contact me by email.

I hope that CA-Mobile API will be to helpfull in your future projects, Enjoy it!

Demo of app developed with CA-Mobile API:

viernes, 8 de abril de 2011

[Java] Draw & moving images inside an Applet using Doble Buffer Technique


Hi, this is the example of how implements the double buffer technique in an Applet, because the procedure it's very different compared with JFrame method.

In this case, I used an instance of Image class to draw in memory all scene, after we will paint it in a single step, this avoid the flicker in the screen when the image is moving.

NOTE: Remind to create a HTML document to use this Applet.

The code of Applet is here:

package mx.gcross.samples;

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
*
* @author René Cruz - G-Cross Studio 2011
*/
public class DobleBufferApplet extends Applet implements KeyListener {
//Empty image for doblebuffer
private Image dobleBuffer;
private Graphics myGraphics;

private Image background;
private Image bird;
int cordX = 20;
int cordY = 30;

public void init() {
background = getImage(getDocumentBase(), "background.jpg");
bird = getImage(getDocumentBase(), "bird.png");

addKeyListener(this);

// Init doble buffer
dobleBuffer = createImage(getWidth(), getHeight());
myGraphics = dobleBuffer.getGraphics();

//Draw images, only the first time
drawImages();
}

@Override
public void update(Graphics g) {
//Draw images in the new positions
drawImages();
//Draw the buffer in the screen
g.drawImage(dobleBuffer, 0, 0, this);
}

public void drawImages() {
myGraphics.drawImage(background, 0, 0, getWidth(), getHeight(), this);
myGraphics.drawImage(bird, cordX, cordY, this);
}

//While a key is pressed
public void keyPressed(KeyEvent ke) {
switch (ke.getKeyCode()) {
//if the right arrow in keyboard is pressed...
case KeyEvent.VK_RIGHT: {
cordX +=3;
}
break;

//if the left arrow in keyboard is pressed...
case KeyEvent.VK_LEFT: {
cordX -=3;
}
break;

//if the down arrow in keyboard is pressed...
case KeyEvent.VK_DOWN: {
cordY +=3;
}
break;

//if the up arrow in keyboard is pressed...
case KeyEvent.VK_UP: {
cordY -=3;
}
break;

}
//call explicit to paint
repaint();


}

//When a key is typed (once)
public void keyTyped(KeyEvent ke) {
}

//When a key is released (typed or pressed)
public void keyReleased(KeyEvent ke) {
}
}

Test the code and comment, thanks!.

If you prefer the complete code source, resources and the HTML document in a Netbeans project, Download It Here!

[Java] Move images inside JFrame using Doble Buffer Technique


Here is an example of how to draw and move images inside JFrame using the Doble Buffer technique and BufferStrategy model.

This technique is used to avoid the flicker in the screen when an image is moving. In case of Applets the doble buffer technique is different, see the next example.

The code here:
package mx.gcross.samples;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;

/**
*
* @author René Cruz - G-Cross Studio 2011
*/
public class DobleBufferJFrame extends JFrame implements KeyListener {

//Objects for images
private BufferedImage background;
private BufferedImage bird;
//First coordinates of bird image
private int cordX = 50;
private int cordY = 250;
//Objects for doble buffer
private BufferStrategy myBuffer;

public DobleBufferJFrame() {
setTitle("Doble Buffer Image Sample");
//set window dimension 480x320px
setSize(512, 512);
//load images...
loadImages();
//make window visible
setVisible(true);
//Ignore OS paint calls
setIgnoreRepaint(true);

//create a doble buffer objects
//NOTE: It's very important to create bufferStrategy after
//JFrame is visible, in other case fail!
this.createBufferStrategy(2);
myBuffer = this.getBufferStrategy();
//call explicit to paint first time
repaint();
}

public void loadImages() {
try {
//path for image file
String pathBackground = "images/background.jpg";
background = ImageIO.read(new File(pathBackground));
String pathBird = "images/bird.png";
bird = ImageIO.read(new File(pathBird));

} catch (IOException ex) {
ex.printStackTrace();
}
//asociate the keyboard listener with this JFrame
addKeyListener(this);
}

public void drawImages(Graphics2D g) {
//draw brackground image (first image)
g.drawImage(background, 0, 0, this);
//draw bird image (second image, in this order)
g.drawImage(bird, cordX, cordY, this);
}

public void paint(Graphics g) {
Graphics2D g2 = null;
if (myBuffer != null) {
try {
//get the graphics2d object of the buffer
g2 = (Graphics2D) myBuffer.getDrawGraphics();
//draw images in buffer
drawImages(g2);
} finally {
g2.dispose();
}
//draw the content of buffer in the screen
myBuffer.show();
}
}

public static void main(String[] args) {
new DobleBufferJFrame();
}

//While a key is pressed
public void keyPressed(KeyEvent ke) {
switch (ke.getKeyCode()) {
//if the right arrow in keyboard is pressed...
case KeyEvent.VK_RIGHT: {
cordX ++;
}
break;

//if the left arrow in keyboard is pressed...
case KeyEvent.VK_LEFT: {
cordX --;
}
break;

//if the down arrow in keyboard is pressed...
case KeyEvent.VK_DOWN: {
cordY ++;
}
break;

//if the up arrow in keyboard is pressed...
case KeyEvent.VK_UP: {
cordY --;
}
break;

}
//call explicit to paint
repaint();


}

//When a key is typed (once)
public void keyTyped(KeyEvent ke) {
}

//When a key is released (typed or pressed)
public void keyReleased(KeyEvent ke) {
}
}

Test the code and comment, thanks!.

If you prefer the complete code source and resources in a Netbeans project, Download It Here!