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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * PlayVideo.java
 *
 * © Research In Motion, 2003-2007
 * Confidential and proprietary.
 */

//package com.samples.videoPlayback;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.StreamConnection;
import javax.microedition.media.Player;
import javax.microedition.media.Manager;
import javax.microedition.media.control.VideoControl;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.system.Characters;




/**
 * 
 */
public final class PlayVideo extends UiApplication
{    

    private Player player;
    private VideoControl videoControl;

    
    public static void main(String[] args)
    {
    	   System.out.println("~~~~HTTPVideo1~~~~~~");
            PlayVideo theApp = new PlayVideo();
     	   System.out.println("~~~~HTTPVideo2~~~~~~");
            theApp.enterEventDispatcher();
     	   System.out.println("~~~~HTTPVideo3~~~~~~");
    }
    
    public PlayVideo()
    {
        MainScreen ms = new MainScreen(){
            
            public boolean onClose()
            {
                //Clean up the player resources.
                player.close();
                videoControl.setVisible(false);
                close();
                return true;
            }
            
            //Override keyChar to capture key commands used to control video playback.
            protected boolean keyChar(char c, int status, int time)
            {
                boolean retVal = false;
                
                if (c == Characters.SPACE)
                {
                    if (player.getState() == Player.STARTED)
                    {
                        //Stop playback.
                        try
                        {
                            player.stop();
                        }
                        catch (Exception ex)
                        {
                            System.out.println("Exception: " + ex.toString());
                        }
                    }
                    else
                    {
                        //Start playback.
                        try
                        {
                            player.start();
                        }
                        catch (Exception ex)
                        {
                            System.out.println("Exception: " + ex.toString());
                        }
                    }
                    
                    retVal = true;
                }
                
                return retVal;
            }
        };
        
        ms.setTitle(new LabelField("Let's play some video..."));
        LabelField lf = new LabelField("Press space to start/stop/resume playback.");
        ms.add(lf);
        pushScreen(ms);
        
        try
        {
            //Create a new Player pointing to the video file.
            //This can use any valid URL.
         //   player = Manager.createPlayer("file:///SDCard/eggs.3gp");
            
            StreamConnection s = null;
            s = (StreamConnection)Connector.open("http://10.252.9.15/eggs.3gp");
            HttpConnection c = (HttpConnection)s;                        
            InputStream i = c.openInputStream();
           // int status = httpConn.getResponseCode();
            
          	//HttpConnection c = (HttpConnection)Connector.open("http://10.252.9.15/eggs.3gp");
//            int rc = c.getResponseCode();
//            if (rc != HttpConnection.HTTP_OK) {
//                throw new IOException("HTTP response code: " + rc);
//            }
          	System.out.println("~~~~~I have a connection?~~~~~~" + c);
          	//the stream looks like it's the problem.
          	System.out.println("~~~~~I have a URL?~~~~" + c.getURL());
          	
          	//these don't work either? WTF?
          	System.out.println("~~~~~I have a type?~~~~" + c.getType());
          	System.out.println("~~~~~I have a status?~~~~~~" + c.getResponseCode());
          	
          	//if i have a connection, why can't i use it!? It has NOTHING to do with that player....
          	
          	
          	System.out.println("~~~~~I have a stream?~~~~~~" + i);
             //System.out.println(c);
             player = Manager.createPlayer(i, c.getType());
             System.out.println("~~~~~~~Anything");
            player.realize();
            
            //Create a new VideoControl.
            videoControl = (VideoControl)player.getControl("VideoControl");
            //Initialize the video mode using a Field.
            videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
            
            //Set the video control to be visible.
            videoControl.setVisible(true);
        }
        catch (Exception ex)
        {
            System.out.println(ex.toString());
        }
    }
}