点击按钮打开一个新的窗口 关键词(Intent, setData , putExtra , startActivity |Bundle)

本文详细介绍了M3U8_Video_demo项目的实现原理,包括如何通过Intent启动VideoActivity来播放M3U8链接的视频,以及如何在接收端解析Intent获取视频源和标题。同时,还提供了一个异步任务的例子,展示了如何使用Bundle传递参数并启动WatchTvActivity。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

M3U8_Video_demo 项目

//------------------ 创建发送
private void playVideo(String source, String title) {
if (source == null || source.equals("")) {
Toast.makeText(this, "视频内容不存在!", Toast.LENGTH_LONG).show();
source = "http://ad.i5suoi.com/video/94.m3u8";
Intent intent = new Intent(this, VideoActivity.class);//VideoActivity 是一个完整的xml 窗口

intent.setData(Uri.parse(source));
intent.putExtra("mVideoTitle", title);
startActivity(intent);
} else {
Intent intent = new Intent(this, VideoActivity.class);
intent.setData(Uri.parse(source));//m3u8链接 链接都必须Uri.parse 处理吧?

intent.putExtra("mVideoTitle", title);//播放标题
        startActivity(intent);//开始新窗体?
}
}
//-----------------接收
初始化的时候调用
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.play_video);

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, POWER_LOCK);

Uri uriPath = getIntent().getData();//m3u8链接

mVideoTitle = getIntent().getStringExtra("mVideoTitle");//播放标题

if (null != uriPath) {
String scheme = uriPath.getScheme();
if (null != scheme) {
mVideoSource = uriPath.toString();
} else {
mVideoSource = uriPath.getPath();
}
}

initUI();
android-tivi github项目
///-----方法2

protected Void doInBackground(Integer... params) {//创建
int id = params[0];
intent = new Intent(getActivity().getApplicationContext(), WatchTvActivity.class);//WatchTvActivity 是一个完整的窗体

Bundle bundle = new Bundle();
bundle.putInt("id", id);//传递id索引
intent.putExtras(bundle);
return null;
}
protected void onPostExecute(Void aVoid) {//检查
super.onPostExecute(aVoid);//这是个异步处理
if (dialog != null) dialog.dismiss();
startActivity(intent);//打开
}
//--------获取
Bundle bundle = getIntent().getExtras();
id = bundle.getInt("id");
 

转载于:https://www.cnblogs.com/marklove/p/10464975.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值