StreamContent.ets 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. import TitleBar from './TitleBar'
  2. import { router } from '@kit.ArkUI';
  3. import { CommonConstants } from '../common/constants/CommonConstants';
  4. import Logger from '../common/util/Logger';
  5. import { VideoItem } from '../viewmodel/VideoItem';
  6. // import { AdSlot, AdSlotBuilder,
  7. // CSJAdCreator,
  8. // CSJAdSdk, CSJNativeExpressAd, NativeExpressAdListener } from '@csj/openadsdk';
  9. import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils';
  10. import { ArrayList } from '@kit.ArkTS';
  11. import { CSJUtil } from '../common/util/CSJUtil';
  12. import { Utility } from '../common/util/Utility';
  13. import { DialogHelper } from '@pura/harmony-dialog';
  14. import { AppUtil, PreferencesUtil, StrUtil, ToastUtil } from '@pura/harmony-utils';
  15. import { common } from '@kit.AbilityKit';
  16. const context = getContext(this) as common.UIAbilityContext;
  17. @Preview
  18. @Component
  19. export struct StreamContent{
  20. @State bundleName:string =''
  21. @State textStr:string = ''
  22. @State videoInList: Array<VideoItem> = []
  23. @Consume isShowDrawer:boolean;
  24. @Consume offsetX: number ;
  25. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  26. .setTitleTextStyle(FontStyle.Normal)
  27. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  28. .setLeftIcon($r('app.media.menu'))
  29. .setLeftIconWidth(25)
  30. .setLeftIconHeight(25)
  31. .setTitleName("流媒体播放")
  32. .setTitleFontColor(Color.White)
  33. .setTitleBarBackground($r('app.color.title_bar_bg'))
  34. .setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
  35. .setOnLeftClickListener(()=>{
  36. animateTo({ duration: 800 }, () => {
  37. // 动画闭包内控制Image组件的出现和消失
  38. this.isShowDrawer = true
  39. this.offsetX = 0
  40. })
  41. })
  42. // 组件生命周期
  43. async aboutToAppear() {
  44. //穿山甲
  45. // this.loadBannerAd( CSJUtil.getBannerID())
  46. this.bundleName = await AppUtil.getBundleName()
  47. }
  48. // 组件消失生命周期
  49. aboutToDisappear() {
  50. console.info('LifeCycleComponent aboutToDisappear');
  51. }
  52. showHaopingDialog(){
  53. DialogHelper.showCustomContentDialog({
  54. dialogId:'haoping',
  55. title: "该功能免费",
  56. autoCancel: false, //点击遮障层时,不关闭弹窗
  57. backCancel: true, //点击返回键,不关闭弹窗
  58. contentBuilder: () => {
  59. this.customHaoPingBuilder("如果您觉得好用可以给个好评吗?谢谢!\n给个好评吧,非常感谢您的支持!")
  60. },
  61. buttons: [],
  62. })
  63. }
  64. doPlay(){
  65. if(StrUtil.isEmpty(this.textStr)){
  66. return
  67. }
  68. if(this.textStr.indexOf("douyin.com") !== -1)
  69. {
  70. ToastUtil.showToast('不支持抖音的复制的链接。')
  71. return
  72. }
  73. if(Utility.isHaoFreeTime()){
  74. let isHao:boolean = PreferencesUtil.getBooleanSync('is_haoping');
  75. if(!isHao){
  76. this.showHaopingDialog()
  77. return
  78. }
  79. }
  80. let item = new VideoItem('',this.textStr,this.textStr,0,0,'')
  81. this.videoInList.push(item)
  82. router.pushUrl({ url: "pages/IjkVideoPlayerPage", params: {
  83. name: item.filePath,
  84. index: 0,
  85. playType:2,//0:连续播放 1:单片重复播放 2:正常播放
  86. videoUrl: item.filePath,
  87. globalVideoList: this.videoInList
  88. } }).catch((err: Error) => {
  89. Logger.error('[IndexTabLocalList] router error: ' + JSON.stringify(err))
  90. });
  91. // router.pushUrl({
  92. // url: CommonConstants.PAGE,
  93. // params: {
  94. // src: this.textStr,
  95. // iSrc: this.textStr,
  96. // index: 0,
  97. // type: CommonConstants.TYPE_INTERNET,
  98. // globalVideoList:this.videoInList
  99. // }
  100. // }).catch((err: Error) => {
  101. // Logger.error('[IndexTabLocalList] router error: ' + JSON.stringify(err))
  102. // });
  103. }
  104. //好评的自定义内容
  105. @Builder
  106. customHaoPingBuilder(content: string) {
  107. Column() {
  108. Text(content)
  109. .fontColor(Color.Gray)
  110. .fontSize(16)
  111. .alignSelf(ItemAlign.Start)
  112. .margin({bottom:15})
  113. .fontSize(16)
  114. Row(){
  115. Button('取消')
  116. .fontColor(Color.White)
  117. .backgroundColor($r('app.color.title_bar_bg'))
  118. //.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  119. .height(50)
  120. .layoutWeight(1)
  121. .stateEffect(true)
  122. .margin({right:6})
  123. .onClick(()=>{
  124. DialogHelper.closeDialog('haoping'); //关闭弹框
  125. })
  126. Button('好评')
  127. .fontColor(Color.White)
  128. //.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
  129. .layoutWeight(1)
  130. .height(50)
  131. .backgroundColor($r('app.color.title_bar_bg'))
  132. .stateEffect(true)
  133. .margin({left:6})
  134. .onClick(()=>{
  135. DialogHelper.closeDialog('haoping'); //关闭弹框
  136. Utility.gotoMarket(context,this.bundleName)
  137. PreferencesUtil.putSync("is_haoping", true);
  138. })
  139. }
  140. }
  141. .width("100%")
  142. .padding(10)
  143. }
  144. build() {
  145. Scroll(){
  146. Column() {
  147. TitleBar({ model: $titleBarModel })
  148. Column(){
  149. Text('请在下方输入流媒体链接:')
  150. .fontSize(12)
  151. .fontWeight(300)
  152. .visibility(Visibility.None)
  153. .fontColor(Color.Grey)
  154. .margin({ top: 20,bottom:20 })
  155. TextArea({placeholder:'请在下方输入流媒体链接:如http://',text:CommonConstants.DEMO_MAGNET})
  156. .type(TextAreaType.NORMAL)
  157. .height(100)
  158. .maxLines(3)
  159. .margin({top:20,right:20,left:20})
  160. .onChange((val:string)=>{
  161. this.textStr = val
  162. })
  163. //穿山甲
  164. // if (this.isShowAd) {
  165. // NodeContainer(this.bannerAd.getAdComponent())
  166. // .width(this.mAdSlot.getAcceptWidth())
  167. // .height(this.mAdSlot.getAcceptHeight())
  168. // .alignSelf(ItemAlign.Center)
  169. // .align(Alignment.Center);
  170. // }
  171. Column() {
  172. Button('播放', { type: ButtonType.Capsule, stateEffect: true })
  173. .width('80%')
  174. .height(55)
  175. .margin({ top: 30, bottom: 20 })
  176. // .linearGradient({
  177. // direction: GradientDirection.Right,
  178. // colors: [['#ff37a0fc', 0.0], ['#f5856e', 0.5], ['#67e667', 1.0]]
  179. // })
  180. .backgroundColor($r('app.color.title_bar_bg'))
  181. .onClick(() => {
  182. this.doPlay()
  183. })
  184. }
  185. }
  186. .width('100%')
  187. .height('100%')
  188. .backgroundColor(Color.White)
  189. }
  190. }
  191. }
  192. //
  193. // /**
  194. // * 穿山甲banner广告
  195. // */
  196. // private declare bannerAd: CSJNativeExpressAd;
  197. // @State private status: string = "未加载"
  198. // @State private isShowAd: boolean = false
  199. // private declare mAdSlot: AdSlot;
  200. // private mBiddingAdm = '' //服务端bidding才需要设置
  201. // private expressLoadAdListener: NativeExpressAdListener = {
  202. // /**
  203. // * 加载失败的回调
  204. // *
  205. // * @param code
  206. // * @param message
  207. // */
  208. // onError: (code: number, message: string) => {
  209. // console.error("加载广告失败,code=" + code + ",message=" + message);
  210. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  211. // },
  212. //
  213. // /**
  214. // * 广告加载成功的回调,接入方可以在这个回调中进行渲染
  215. // *
  216. // * @param ads 返回的广告列表
  217. // */
  218. //
  219. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  220. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  221. // if (ads && ads.length > 0) {
  222. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  223. // ad.setExpressInteractionListener({
  224. // /**
  225. // *广告的点击回调
  226. // * @param type 广告的交互类型
  227. // */
  228. // onAdClicked: (type: number) => {
  229. // console.log("BannerExpressAdPage==onAdClicked......");
  230. // },
  231. //
  232. // /**
  233. // * 广告的展示回调 每个广告仅回调一次
  234. // * @param type 广告的交互类型
  235. // */
  236. // onAdShow: (type: number) => {
  237. // console.log("BannerExpressAdPage==onAdShow......");
  238. // },
  239. //
  240. // /**
  241. // * 模板渲染失败
  242. // */
  243. // onRenderFail: (code: number, msg: string) => {
  244. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  245. // },
  246. //
  247. // /**
  248. // * 模板渲染成功
  249. // * @param width 返回view的宽 单位 vp
  250. // * @param height 返回view的高 单位 vp
  251. // */
  252. // onRenderSuccess: (width: number, height: number) => {
  253. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  254. // this.bannerAd = ad;
  255. // this.status = "广告加载完成待展示";
  256. //
  257. // this.showBannerAd()
  258. // }
  259. // })
  260. // //渲染广告
  261. // ad.setSlideIntervalTime(30 * 1000);//设置轮播时间长
  262. // this.setDislikeCallback(ad); //设置dislike
  263. // ad.render(this.getUIContext())
  264. // this.status = "广告加载中...";
  265. // });
  266. // }
  267. // }
  268. // }
  269. //
  270. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  271. // ad.setDislikeCallback({
  272. // /**
  273. // * dislike show
  274. // */
  275. // onShow: () => {
  276. // console.log("BannerExpressAdPage==dislike......show");
  277. // },
  278. //
  279. // /**
  280. // * @param position 选择的位置
  281. // * @param value 选择的内容
  282. // * @param enforceRemove 是否强制关闭广告
  283. // */
  284. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  285. // this.isShowAd = false;
  286. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value + ",enforce=" + enforceRemove);
  287. // },
  288. //
  289. // /**
  290. // * 点击取消
  291. // */
  292. // onCancel: () => {
  293. // console.log("BannerExpressAdPage==dislike......onCancel");
  294. // }
  295. //
  296. // })
  297. // }
  298. //
  299. // /**
  300. // * 加载Banner广告
  301. // */
  302. // loadBannerAd(rit: string) {
  303. // if(!Utility.isNoble()){
  304. // return
  305. // }
  306. // if(!Utility.isPassInstallTime(2)){
  307. // return
  308. // }
  309. // // if(!Utility.isFreeTime())
  310. // // return
  311. // this.isShowAd = false;
  312. // let adCreator:CSJAdCreator = CSJAdSdk.getAdCreator()
  313. // this.mAdSlot = new AdSlotBuilder()
  314. // .setCodeId(rit)
  315. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  316. // .setAdCount(1)
  317. // .setBidAdm(this.mBiddingAdm)
  318. // .build()
  319. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  320. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  321. // this.status = "广告加载中..."
  322. // }
  323. //
  324. // /**
  325. // * 展示Banner广告
  326. // */
  327. // showBannerAd() {
  328. // if (!this.bannerAd) {
  329. // return
  330. // }
  331. // this.isShowAd = true
  332. // this.status = "已展示"
  333. // }
  334. /**
  335. * 穿山甲广告代码结束
  336. */
  337. }