| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- import TitleBar from './TitleBar'
- import { router } from '@kit.ArkUI';
- import { CommonConstants } from '../common/constants/CommonConstants';
- import Logger from '../common/util/Logger';
- import { VideoItem } from '../viewmodel/VideoItem';
- // import { AdSlot, AdSlotBuilder,
- // CSJAdCreator,
- // CSJAdSdk, CSJNativeExpressAd, NativeExpressAdListener } from '@csj/openadsdk';
- import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils';
- import { ArrayList } from '@kit.ArkTS';
- import { CSJUtil } from '../common/util/CSJUtil';
- import { Utility } from '../common/util/Utility';
- import { DialogHelper } from '@pura/harmony-dialog';
- import { AppUtil, PreferencesUtil, StrUtil, ToastUtil } from '@pura/harmony-utils';
- import { common } from '@kit.AbilityKit';
- const context = getContext(this) as common.UIAbilityContext;
- @Preview
- @Component
- export struct StreamContent{
- @State bundleName:string =''
- @State textStr:string = ''
- @State videoInList: Array<VideoItem> = []
- @Consume isShowDrawer:boolean;
- @Consume offsetX: number ;
- @State titleBarModel: TitleBar.Model = new TitleBar.Model()
- .setTitleTextStyle(FontStyle.Normal)
- .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
- .setLeftIcon($r('app.media.menu'))
- .setLeftIconWidth(25)
- .setLeftIconHeight(25)
- .setTitleName("流媒体播放")
- .setTitleFontColor(Color.White)
- .setTitleBarBackground($r('app.color.title_bar_bg'))
- .setTitleBarBottomLineColor($r('app.color.title_bar_bg'))
- .setOnLeftClickListener(()=>{
- animateTo({ duration: 800 }, () => {
- // 动画闭包内控制Image组件的出现和消失
- this.isShowDrawer = true
- this.offsetX = 0
- })
- })
- // 组件生命周期
- async aboutToAppear() {
- //穿山甲
- // this.loadBannerAd( CSJUtil.getBannerID())
- this.bundleName = await AppUtil.getBundleName()
- }
- // 组件消失生命周期
- aboutToDisappear() {
- console.info('LifeCycleComponent aboutToDisappear');
- }
- showHaopingDialog(){
- DialogHelper.showCustomContentDialog({
- dialogId:'haoping',
- title: "该功能免费",
- autoCancel: false, //点击遮障层时,不关闭弹窗
- backCancel: true, //点击返回键,不关闭弹窗
- contentBuilder: () => {
- this.customHaoPingBuilder("如果您觉得好用可以给个好评吗?谢谢!\n给个好评吧,非常感谢您的支持!")
- },
- buttons: [],
- })
- }
- doPlay(){
- if(StrUtil.isEmpty(this.textStr)){
- return
- }
- if(this.textStr.indexOf("douyin.com") !== -1)
- {
- ToastUtil.showToast('不支持抖音的复制的链接。')
- return
- }
- if(Utility.isHaoFreeTime()){
- let isHao:boolean = PreferencesUtil.getBooleanSync('is_haoping');
- if(!isHao){
- this.showHaopingDialog()
- return
- }
- }
- let item = new VideoItem('',this.textStr,this.textStr,0,0,'')
- this.videoInList.push(item)
- router.pushUrl({ url: "pages/IjkVideoPlayerPage", params: {
- name: item.filePath,
- index: 0,
- playType:2,//0:连续播放 1:单片重复播放 2:正常播放
- videoUrl: item.filePath,
- globalVideoList: this.videoInList
- } }).catch((err: Error) => {
- Logger.error('[IndexTabLocalList] router error: ' + JSON.stringify(err))
- });
- // router.pushUrl({
- // url: CommonConstants.PAGE,
- // params: {
- // src: this.textStr,
- // iSrc: this.textStr,
- // index: 0,
- // type: CommonConstants.TYPE_INTERNET,
- // globalVideoList:this.videoInList
- // }
- // }).catch((err: Error) => {
- // Logger.error('[IndexTabLocalList] router error: ' + JSON.stringify(err))
- // });
- }
- //好评的自定义内容
- @Builder
- customHaoPingBuilder(content: string) {
- Column() {
- Text(content)
- .fontColor(Color.Gray)
- .fontSize(16)
- .alignSelf(ItemAlign.Start)
- .margin({bottom:15})
- .fontSize(16)
- Row(){
- Button('取消')
- .fontColor(Color.White)
- .backgroundColor($r('app.color.title_bar_bg'))
- //.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
- .height(50)
- .layoutWeight(1)
- .stateEffect(true)
- .margin({right:6})
- .onClick(()=>{
- DialogHelper.closeDialog('haoping'); //关闭弹框
- })
- Button('好评')
- .fontColor(Color.White)
- //.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
- .layoutWeight(1)
- .height(50)
- .backgroundColor($r('app.color.title_bar_bg'))
- .stateEffect(true)
- .margin({left:6})
- .onClick(()=>{
- DialogHelper.closeDialog('haoping'); //关闭弹框
- Utility.gotoMarket(context,this.bundleName)
- PreferencesUtil.putSync("is_haoping", true);
- })
- }
- }
- .width("100%")
- .padding(10)
- }
- build() {
- Scroll(){
- Column() {
- TitleBar({ model: $titleBarModel })
- Column(){
- Text('请在下方输入流媒体链接:')
- .fontSize(12)
- .fontWeight(300)
- .visibility(Visibility.None)
- .fontColor(Color.Grey)
- .margin({ top: 20,bottom:20 })
- TextArea({placeholder:'请在下方输入流媒体链接:如http://',text:CommonConstants.DEMO_MAGNET})
- .type(TextAreaType.NORMAL)
- .height(100)
- .maxLines(3)
- .margin({top:20,right:20,left:20})
- .onChange((val:string)=>{
- this.textStr = val
- })
- //穿山甲
- // if (this.isShowAd) {
- // NodeContainer(this.bannerAd.getAdComponent())
- // .width(this.mAdSlot.getAcceptWidth())
- // .height(this.mAdSlot.getAcceptHeight())
- // .alignSelf(ItemAlign.Center)
- // .align(Alignment.Center);
- // }
- Column() {
- Button('播放', { type: ButtonType.Capsule, stateEffect: true })
- .width('80%')
- .height(55)
- .margin({ top: 30, bottom: 20 })
- // .linearGradient({
- // direction: GradientDirection.Right,
- // colors: [['#ff37a0fc', 0.0], ['#f5856e', 0.5], ['#67e667', 1.0]]
- // })
- .backgroundColor($r('app.color.title_bar_bg'))
- .onClick(() => {
- this.doPlay()
- })
- }
- }
- .width('100%')
- .height('100%')
- .backgroundColor(Color.White)
- }
- }
- }
- //
- // /**
- // * 穿山甲banner广告
- // */
- // private declare bannerAd: CSJNativeExpressAd;
- // @State private status: string = "未加载"
- // @State private isShowAd: boolean = false
- // private declare mAdSlot: AdSlot;
- // private mBiddingAdm = '' //服务端bidding才需要设置
- // private expressLoadAdListener: NativeExpressAdListener = {
- // /**
- // * 加载失败的回调
- // *
- // * @param code
- // * @param message
- // */
- // onError: (code: number, message: string) => {
- // console.error("加载广告失败,code=" + code + ",message=" + message);
- // this.status = "加载广告失败,code=" + code + ",message=" + message;
- // },
- //
- // /**
- // * 广告加载成功的回调,接入方可以在这个回调中进行渲染
- // *
- // * @param ads 返回的广告列表
- // */
- //
- // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
- // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
- // if (ads && ads.length > 0) {
- // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
- // ad.setExpressInteractionListener({
- // /**
- // *广告的点击回调
- // * @param type 广告的交互类型
- // */
- // onAdClicked: (type: number) => {
- // console.log("BannerExpressAdPage==onAdClicked......");
- // },
- //
- // /**
- // * 广告的展示回调 每个广告仅回调一次
- // * @param type 广告的交互类型
- // */
- // onAdShow: (type: number) => {
- // console.log("BannerExpressAdPage==onAdShow......");
- // },
- //
- // /**
- // * 模板渲染失败
- // */
- // onRenderFail: (code: number, msg: string) => {
- // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
- // },
- //
- // /**
- // * 模板渲染成功
- // * @param width 返回view的宽 单位 vp
- // * @param height 返回view的高 单位 vp
- // */
- // onRenderSuccess: (width: number, height: number) => {
- // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
- // this.bannerAd = ad;
- // this.status = "广告加载完成待展示";
- //
- // this.showBannerAd()
- // }
- // })
- // //渲染广告
- // ad.setSlideIntervalTime(30 * 1000);//设置轮播时间长
- // this.setDislikeCallback(ad); //设置dislike
- // ad.render(this.getUIContext())
- // this.status = "广告加载中...";
- // });
- // }
- // }
- // }
- //
- // private setDislikeCallback(ad: CSJNativeExpressAd) {
- // ad.setDislikeCallback({
- // /**
- // * dislike show
- // */
- // onShow: () => {
- // console.log("BannerExpressAdPage==dislike......show");
- // },
- //
- // /**
- // * @param position 选择的位置
- // * @param value 选择的内容
- // * @param enforceRemove 是否强制关闭广告
- // */
- // onSelected: (position: number, value: string, enforceRemove: boolean) => {
- // this.isShowAd = false;
- // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value + ",enforce=" + enforceRemove);
- // },
- //
- // /**
- // * 点击取消
- // */
- // onCancel: () => {
- // console.log("BannerExpressAdPage==dislike......onCancel");
- // }
- //
- // })
- // }
- //
- // /**
- // * 加载Banner广告
- // */
- // loadBannerAd(rit: string) {
- // if(!Utility.isNoble()){
- // return
- // }
- // if(!Utility.isPassInstallTime(2)){
- // return
- // }
- // // if(!Utility.isFreeTime())
- // // return
- // this.isShowAd = false;
- // let adCreator:CSJAdCreator = CSJAdSdk.getAdCreator()
- // this.mAdSlot = new AdSlotBuilder()
- // .setCodeId(rit)
- // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
- // .setAdCount(1)
- // .setBidAdm(this.mBiddingAdm)
- // .build()
- // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
- // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
- // this.status = "广告加载中..."
- // }
- //
- // /**
- // * 展示Banner广告
- // */
- // showBannerAd() {
- // if (!this.bannerAd) {
- // return
- // }
- // this.isShowAd = true
- // this.status = "已展示"
- // }
- /**
- * 穿山甲广告代码结束
- */
- }
|