| 请先登录 | 注册 |
| IPSC1978.GICP.NET |
| ■标题:ExoPlayer - MediaPlayer / VideoView 替代方案 媒体播放器 |
| ■作者:IPSC [2026/8/21 10:20:57] 这是原网贴子https://www.b4x.com/android/forum/threads/exoplayer-mediaplayer-videoview-alternative.72652/#content 库下载:https://www.b4x.com/android/forum/attachments/exoplayer-zip.119364/ 例子下载:https://www.b4x.com/android/forum/attachments/exoplayerexample-zip.103110/ 库额外文件,放库文件夹:https://www.b4x.com/android/files/exoplayer-additional_libs.zip 我学会了在B4XPAGE模式下用作背景音乐的办法,如下 先把123.mp3文件复制到files文件夹 在B4A中选中EXOPLAYER库 在B4XMAINPAGE等页面里,先在Sub Class_Globals加入定义 Private player1 As SimpleExoPlayer'这种是无界面的 'Private SimpleExoPlayerView1 As SimpleExoPlayerView'这种有界面 然后加几个SUB块,如下: [vb] Sub InitializePlayer player1.Initialize("player") 'player1.Prepare(player1.CreateFileSource(File.DirAssets, "1.mp3"))'单曲只播放一次 'player1.Prepare(player1.CreateLoopSource(player1.CreateFileSource(File.DirAssets, "1.mp3"),-1))'单曲无限循环 '下面是列表播放 Dim sources As List sources.Initialize sources.Add(player1.CreateFileSource(File.DirAssets, "1.mp3")) sources.Add(player1.CreateFileSource(File.DirAssets, "2.mp3")) sources.Add(player1.CreateFileSource(File.DirAssets, "3.mp3")) sources.Add(player1.CreateFileSource(File.DirAssets, "4.mp3")) 'player1.Prepare(player1.CreateListSource(sources))'列表播放1次 player1.Prepare(player1.CreateLoopSource(player1.CreateListSource(sources), -1))'列表循环播放 player1.Play End Sub ' 当页面出现在前台时 Private Sub B4XPage_Appear ' 如果希望页面可见时自动恢复播放 player1.Play End Sub ' 当页面消失(切换到其他页面或后台)时 Private Sub B4XPage_Disappear ' 建议在此处暂停播放,避免后台噪音或资源浪费 player1.Pause End Sub ' 当页面被销毁时(彻底关闭) Private Sub B4XPage_Dismissed ' 必须释放资源,防止内存泄漏 player1.Release player1 = Null End Sub [/vb] 最后,在 Private Sub B4XPage_Created (Root1 As B4XView) 里引用 InitializePlayer 以上都是测试可用的,视频播放自己还没测试,请参阅官网论坛贴子。 【回复/版区/上篇/下篇/发贴/仅文字/HTML】 |
| 【倒序/最近21条回复】(暂无) |
| (查看完整版网页) |
| 短讯|首页|登录|算法|电脑版 . DK MiniBBS Plus v2.0 mm0759.com 64 毫秒 . |