Android中通过网络获取json数据来播放视频
为了实现 本地化的测试 ,要新建 一个java 类做为 服务端 让手机来访问
把json放到你服务端tomcat 中 如图 :
json数据 的内容 为:
[java]
{
"videos":[
{
"id":"1",
"title":"泡芙易做图的灯泡",
"image":"http://172.22.64.28:8080/doudou/images/fu.jpg",
"duration":"910",
"category":"原创",
"state":"normal",
"published":"2011-07-15 09:00:42",
"description":"当一个人在一座城市搬11次家。就意味着准备在这个城市买房了",
"player":"http://172.22.64.28:8080/doudou/video/oppo.3gp"
},
{
"id":"2",
"title":"爱在春天",
"image":"http://172.22.64.28:8080/doudou/images/spring.jpg",
"duration":"910",
"category":"原创",
"state":"normal",
"published":"2013-04-15 09:00:42",
"description":"上世纪30年代中期,整个中国动荡不安,几个年轻女孩依然怀抱着勇气,追寻着理想与爱情。",
"player":"http://172.22.64.28:8080/doudou/video/hao.3gp"
}
}
}
{
"videos":[
{
"id":"1",
"title":"泡芙易做图的灯泡",
"image":"http://172.22.64.28:8080/doudou/images/fu.jpg",
"duration":"910",
"category":"原创",
"state":"normal",
"published":"2011-07-15 09:00:42",
"description":"当一个人在一座城市搬11次家。就意味着准备在这个城市买房了",
"player":"http://172.22.64.28:8080/doudou/video/oppo.3gp"
},
{
"id":"2",
"title":"爱在春天",
"image":"http://172.22.64.28:8080/doudou/images/spring.jpg",
"duration":"910",
"category":"原创",
"state":"normal",
"published":"2013-04-15 09:00:42",
"description":"上世纪30年代中期,整个中国动荡不安,几个年轻女孩依然怀抱着勇气,追寻着理想与爱情。",
"player":"http://172.22.64.28:8080/doudou/video/hao.3gp"
}
}
}
[java]
public class ListVideoActivity extends Activity {
// 获取视频数据的地址
private String path = "http://172.22.64.28:8080/doudou/video.json";
// 接受服务器端响应的数据
private String content;
// 声明listView控件
private ListView listView;
// 声明handler对象
private Handler handler;
private static final int INTENTDATA = 1;
public JSONArray array;
public LayoutInflater inflater;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_video);
// 根据服务获取inflater对象
inflater = (LayoutInflater) this
.getSystemService(LAYOUT_INFLATER_SERVICE);
// 发送请求 获取网络数据
sendGet();
// 获取控件对象
listView = (ListView) findViewById(R.id.lv_videos);
// 实例化 handler操作
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case INTENTDATA:
// 获取数据
补充:移动开发 , Android ,