android使用videoview播放視頻
public class Activity01 extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final VideoView videoView = (VideoView) findViewById(R.id.VideoView01);
Button PauseButton = (Button) this.findViewById(R.id.PauseButton);
Button LoadButton = (Button) this.findViewById(R.id.LoadButton);
Button PlayButton = (Button) this.findViewById(R.id.PlayButton);
// load
LoadButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0)
{
// videoView.setVideoPath("/sdcard/test.mp4");
videoView.setVideoPath("android.resource://com.homer/"+R.raw.china);
videoView.setMediaController(new MediaController(Activity01.this));
videoView.requestFocus();
}
});
// play
PlayButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0)
{
videoView.start();
}
});
// pause
PauseButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0)
{
videoView.pause();
}
});
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<VideoView
android:id="@+id/VideoView01"
android:layout_width="320px"
android:layout_height="240px" />
<Button
android:id="@+id/LoadButton"
android:layout_width="80px"
android:layout_height="wrap_content"
android:layout_x="30px"
android:layout_y="300px"
android:text="裝載" />
<Button
android:id="@+id/PlayButton"
android:layout_width="80px"
android:layout_height="wrap_content"
android:layout_x="120px"
android:layout_y="300px"
android:text="播放" />
<Button
android:id="@+id/PauseButton"
android:layout_width="80px"
android:layout_height="wrap_content"
android:layout_x="210px"
android:layout_y="300px"
android:text="暫停" />
</AbsoluteLayout>
- Android UniversalVideoView實(shí)現(xiàn)視頻播放器
- Android音視頻開發(fā)之VideoView使用指南
- Android自定義videoview仿抖音界面
- Android原生視頻播放VideoView的使用
- android多媒體類VideoView使用方法詳解
- Android編程實(shí)現(xiàn)VideoView循環(huán)播放功能的方法
- Android多媒體之VideoView視頻播放器
- Android VideoView類實(shí)例講解
- Android使用VideoView播放本地視頻和網(wǎng)絡(luò)視頻的方法
- Android中VideoView音視頻開發(fā)的實(shí)現(xiàn)
相關(guān)文章
最新Android版本、代號(hào)、對(duì)應(yīng)API/NDK級(jí)別、發(fā)布時(shí)間及市場(chǎng)份額
這篇文章主要介紹了最新Android版本、代號(hào)、對(duì)應(yīng)API/NDK級(jí)別、發(fā)布時(shí)間及市場(chǎng)份額,在開發(fā)Android應(yīng)用時(shí)會(huì)碰到如何選擇Android版本級(jí)API級(jí)別的問(wèn)題,看完這篇文章后相信這個(gè)問(wèn)題會(huì)迎刃而解2017-12-12Android獲取移動(dòng)網(wǎng)絡(luò)信號(hào)強(qiáng)度的方法
這篇文章主要介紹了Android獲取移動(dòng)網(wǎng)絡(luò)信號(hào)強(qiáng)度的方法,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-04-04Kotlin 使用Lambda來(lái)設(shè)置回調(diào)的操作
這篇文章主要介紹了Kotlin 使用Lambda來(lái)設(shè)置回調(diào)的操作方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03Jetpack?Compose慣性衰減動(dòng)畫AnimateDecay詳解
這篇文章主要為大家介紹了Jetpack?Compose慣性衰減動(dòng)畫AnimateDecay詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11Android開發(fā)之圖形圖像與動(dòng)畫(三)Animation效果的XML實(shí)現(xiàn)
使用XML來(lái)定義Tween Animation動(dòng)畫的XML文件在工程中res/anim目錄,這個(gè)文件必須包含一個(gè)根元素,感興趣的友可以了解一下,希望本文對(duì)你有所幫助2013-01-01Android中Activity的四種啟動(dòng)模式和onNewIntent()
android 中activity的啟動(dòng)模式分為四種,(standard、singleTop、singTask、singleInstance),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-08-08Android實(shí)現(xiàn)SwipeRefreshLayout首次進(jìn)入自動(dòng)刷新
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)SwipeRefreshLayout首次進(jìn)入自動(dòng)刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01Android編程簡(jiǎn)單解析JSON格式數(shù)據(jù)的方法示例
這篇文章主要介紹了Android編程簡(jiǎn)單解析JSON格式數(shù)據(jù)的方法,結(jié)合實(shí)例形式分析了Android編程解析json格式數(shù)據(jù)的實(shí)現(xiàn)方法與相關(guān)操作技巧,需要的朋友可以參考下2017-08-08