1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình Android: ứng dụng xem Video pot

3 942 6

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 3
Dung lượng 84,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Ứng dụng xem Video Tring bài viết này, mình sẽ dùng các công cụ có sẵn của Android để xây dựng 1 ứng dụng đơn giản xem video file MP4 trực tiếp ở 1 đường link trên mạng 1/ Tạo Project :

Trang 1

Ứng dụng xem Video Tring bài viết này, mình sẽ dùng các công cụ có sẵn của Android để xây dựng 1 ứng dụng đơn giản xem video (file MP4) trực tiếp ở 1 đường link trên mạng

1/ Tạo Project :

Project name: VideoDemo

Build Target: Android 2.3.3

Application name: VideoDemo

Package name: com.dac.VideoDemo

Create Activity: MainActivity

2/ Trong file giao diện main.xml ta thiết kế:

<?xml version ="1.0" encoding ="utf-8"?>

<! This file is /res/layout/main.xml >

<LinearLayout

android:layout_width ="fill_parent" android:layout_height ="fill_parent"

xmlns:android = http://schemas.android.com/apk/res/android"

/>

</LinearLayout>

3/ Trong file Java chính (MainActivity.java) ta viết code xử lý như sau:

package com.androidbook.videodemo;

import android.app.Activity;

import android.net.Uri;

import android.os.Bundle;

import android.os.Environment;

import android.widget.MediaController;

Trang 2

public class MainActivity extends Activity {

/** Called when the activity is first created */

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

this.setContentView(R.layout.main);

VideoView videoView = (VideoView)this.findViewById(R.id.videoView); MediaController mc = new MediaController(this);

videoView.setMediaController(mc);

videoView.setVideoURI(Uri.parse(

"http://www.androidbook.com/akc/filestorage/android/documentfiles/3389/ movie.mp4"));

videoView.requestFocus();

videoView.start();

}

}

Để truy cập được Internet ta code trong file AndroidManifest.xml như sau:

<?xml version ="1.0" encoding ="utf-8"?>

<manifest xmlns:android ="http://schemas.android.com/apk/res/android"

android:label ="@string/app_name">

<intent-filter>

</intent-filter>

</activity>

</application>

<uses-permission android:name

="android.permission.INTERNET"></uses-permission>

</manifest>

Và khi debug ứng dụng ta thấy đoạn video bắt đầu chạy:

Ngày đăng: 08/08/2014, 16:20

TỪ KHÓA LIÊN QUAN

w