十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
在安卓應(yīng)用里添加一個視頻文件,需要在res中添加一個名為raw(不能亂起)的文件夾,里面存放你要播放的視頻文件

代碼如下:
1.在lanyout中添加一個videoview
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
2.在MainActivity中:
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.VideoView;
public class MainActivity extends Activity {
private VideoView video;
private Button button1;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.begin_video);
video=(VideoView)findViewById(R.id.video1);
button1=(Button)findViewById(R.id.button1);
Uri uri=Uri.parse("android.resource://com.example.agame/"+R.raw.startvideo);//獲得uri video.setVideoURI(uri);//指定要播放的視頻
video.requestFocus();讓video獲得焦點
try{
video.start();//開始播放視頻
}catch(Exception e){
e.printStackTrace();
}
video.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
finish();//結(jié)束
}
});
}
這樣就可以播放視頻啦!?。?/p>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。