简体   繁体   English

Ionic-如何仅播放多个对象中的一个媒体对象

[英]Ionic- How to play only one media object from multiple objects

在此处输入图片说明

There are three Ionic-native media objects in the screen. 屏幕上有三个Ionic-native媒体对象。 I make a code that play the selected one. 我编写了一个播放所选代码的代码。

    play(filename)
    {
       this.curr_playing_file = this.createAudioFile(savfilename);
       this.curr_playing_file.play();
    }

   createAudioFile(filename): MediaObject {
        if (this.platform.is('ios')) {  //ios
          console.log(filename.replace(/^file:\/\//, ''));
          return this.media.create(filename.replace(/^file:\/\//, ''));    
        } else {  // android
          return this.media.create(filename);
      } 
   }

when i click three of them , they are playing at the same time. 当我单击其中三个时,它们会同时播放。 I want to play only one at that time. 当时我只想玩一场。 Please help how can i solve this problem efficiently. 请帮助我如何有效解决此问题。 Thanks. 谢谢。

First you have to check if any other audio is playing and if any other audio is playing you need to stop it and release it before playing the other file 首先,您必须检查是否正在播放其他音频,是否正在播放其他音频,则需要先停止播放并释放它,然后再播放其他文件

if (this.curr_playing_file.mediaStatus == 2)
{
this.curr_playing_file.stop();
this.curr_playing_file.Release();
}
this.media.create(filename);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 ionic Media 插件顺序播放多个音频 - How to play multiple audio sequentially with ionic Media plugin Ionic- ionic serve 显示空白屏幕 Ionic- 关键“viewport-fit”未被识别和忽略 - Ionic- ionic serve shows blank white screen Ionic- The key “viewport-fit” is not recognized and ignored Ionic- Angular:将数据传递给服务 - Ionic- Angular : Pass data to a service 如何使用ionic 2在幻灯片中显示多个对象? - How to display the multiple objects in slide using ionic 2? 如何在ionic 2中一次仅激活一个按钮 - How to active only one button at a time in ionic 2 (IONIC - Angular)我如何在 html 卡中仅显示符合特定条件的 JSON 中的某些对象? - (IONIC - Angular) How can i show in html cards, only certain objects from a JSON that match certain criteria? 如何在angularfire2中显示来自一个对象的相关对象信息 - How to display related objects information from one object in angularfire2 如何使用ionic 2和angular2从多个复选框中仅选中一个复选框 - How to get selected only single checkbox from multiple checkboxes using ionic 2 and angular2 如何仅发布对象中的一个元素? - How can i POST only one element from my object? 如何使用Ionic Storage使用Ionic 3从api存储json对象? - How to use Ionic Storage to store json object from api with ionic 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM