启用禁用Alist的按钮



我创建了一个媒体播放函数NGIF状态,仅在列表中显示一个按钮。在此列表中,当我单击播放按钮(现在停止按钮到达可见状态)时,我希望启用该项目按钮,并且该列表中的其他按钮应禁用。有人可以帮我

 <ion-content padding class="has-header">
    <ion-list>
        <ion-grid>
            <ion-row *ngFor="let file of MyAudioFiles let i = index  ">
                <ion-col width-60 style="padding-top:  6px;">
                    {{file.audio.name}}
                </ion-col>
                <ion-col width-20  > 
                    <ion-icon style="padding-top: 9px;" *ngIf="!file.status" name="play" (click)="startPlayback(file.audio, i)"></ion-icon>
                    <ion-icon style="padding-top: 9px;" *ngIf="file.status" name="square" (click)="stopPlayback(file.audio, i)"></ion-icon>
                </ion-col>               
            </ion-row>
        </ion-grid>
    </ion-list>
</ion-content>
startPlayback(audio, i) {
        try {
            console.log("start playback file name and index", audio.name, i);
            this.MyAudioFiles[i].status = true;
            var pathalone = audio.nativeURL;
            this.file = new MediaPlugin(pathalone, (status) => {
                console.log("playback status", status);
                this.playbackStatus = status
                if (status == 2) {
                    console.log("MEDIA RUNING")
                }
                if (status == 4) {
                    console.log("MEDIA STOPPED")
                    this.MyAudioFiles[i].status = false;
                }
            });
            console.log("play back file getDuration", this.file.getDuration());
            this.file.play();
            console.log("playbackStatus", this.playbackStatus);
        }
        catch (e) {
            this.showAlert('Could not play recording.');
        }
    }

我建议您使用仅图标按钮而不是ion-icon,因为后者没有disabled属性。

<button ion-button style="padding-top: 9px;" *ngIf="!file.status" (click)="startPlayback(file.audio, i)" clear icon-only [disabled]="isPlaying()">
  <ion-icon name="play"></ion-icon>
</button>

您可以根据媒体是否播放文件来定义 isPlaying()返回。

isPlaying(){
  return this.MyAudioFiles.filter(file=>file.status==true).length > 0;
}

相关内容

  • 没有找到相关文章

最新更新