【问题标题】:Audio player for IonicIonic 的音频播放器
【发布时间】:2015-02-15 06:35:10
【问题描述】:

我正在学习 Ionic,想嵌入一个音频播放器。我找到了Video Player 的这个 Plnkr 示例:

    angular.module('app',[])

.directive('youtubeIframe', ['$timeout', function ($timeout, $sce ) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            $timeout( function () {
                var temp1 = '<iframe width="400px" height="200px" src="http://www.youtube.com/embed/';
                var temp2 = '?&autoplay=0&autohide=1&fs=1&cc_load_policy=1&loop=0&rel=0&modestbranding=1&&hd=1&playsinline=0&showinfo=0&theme=light" frameborder="1" allowfullscreen></iframe>';
                var finalvar = temp1 + attrs.youtubeIframe + temp2 ;
                console.log('Finalvar is: ' + finalvar); //just to check if url is ok
                element.prepend( finalvar );
            }, 150);
            // The timeout is to give enough time for the Dom to be built and checked for its structure, so that we can manipulate it.
        }
    };
}])



.controller('VideoCtrl', function($scope) {

    $scope.angularvideos = [
      { 
        name: 'Angular on the go: Using Angular to power Mobile Apps', 
        youtubeId: 'xOAG7Ab_Oz0',
        publishdate: 'Dec 2013'
      },
      { 
        name: 'Crafting the Perfect AngularJS Model and Making it Real Time', 
        youtubeId: 'lHbWRFpbma4',
        publishdate: 'April 2014'
      },
      { 
        name: 'AngularJS & D3: Directives for Visualizations', 
        youtubeId: 'aqHBLS_6gF8',
        publishdate: 'Jan 2014'
      },
      { 
        name: 'The Thick Front End', 
        youtubeId: 'hv2NEW0uC1o',
        publishdate: 'Nov 2013'
      }
    ];
})

在 iframe 中为移动应用(暂时是 Android,但后来在 iOS 上也是如此)中的音频播放器是否有类似的示例?

【问题讨论】:

    标签: android angularjs ionic-framework audio


    【解决方案1】:

    我发布了一个使用 Cordova Media 插件本地播放音频的 Ionic 模块(目前在 Android 上进行了测试)。

    你定义一个 Ionic 视图:

    <ion-view view-title="Music">
      <ion-content>
          <ion-audio-track track="myTrack">
              <div class="list list-inset">
                  <div class="item item-thumbnail-left">
                      <img src="{{track.art}}">
                      <h2>{{track.title}}</h2>
                      <p>{{track.artist}}</p>
                      <ion-audio-play></ion-audio-play>
                  </div>
                  <div class="item">
                    <ion-audio-progress-bar display-time></ion-audio-progress-bar>
                  </div>
              </div>
          </ion-audio-track>
      </ion-content>
    </ion-view>
    

    还有你的范围:

    $scope.myTrack = {
        url: 'https://www.example.com/my_song.mp3',
        artist: 'Somebody',
        title: 'Song name',
        art: 'img/album_art.jpg'
    }
    

    看起来像这样:

    你可以在这里找到它:https://github.com/arielfaur/ionic-audio

    【讨论】:

    • 它可以在浏览器中使用吗?我已在浏览器中签入,但工作正常
    • 不,您需要在您的设备上安装 Cordova Media 插件。我正在研究在浏览器上使用 Web Audio API 的后备方案,但它还没有准备好!
    • 太棒了!!它在模拟器中运行良好。如果您能添加volumenext/prev track 选项,那就太好了。
    【解决方案2】:

    我认为那里有正确的东西-链接:

    Dev-friendly and stable module for audio, html5-video, youtube(iframe) etc..

    这里是Example 创建音频播放器。

    这里是codepen

        <videogular vg-theme="controller.config.theme.url" class="videogular-container audio">
        <vg-media vg-src="controller.config.sources"></vg-media>
    
        <vg-controls>
            <vg-play-pause-button></vg-play-pause-button>
            <vg-time-display>{{ currentTime | date:'mm:ss' }}</vg-time-display>
            <vg-scrub-bar>
                <vg-scrub-bar-current-time></vg-scrub-bar-current-time>
            </vg-scrub-bar>
            <vg-time-display>{{ timeLeft | date:'mm:ss' }}</vg-time-display>
            <vg-volume>
                <vg-mute-button></vg-mute-button>
            </vg-volume>
        </vg-controls>
    </videogular>
    

    【讨论】:

    • 我实际上是从 videogular 开始的,但遇到了问题。如果我将 mm:ss 替换为 hh:mm:ss 由于时区问题,即使上述日期过滤器也会崩溃。
    猜你喜欢
    • 2022-01-14
    • 2023-03-26
    • 2019-02-09
    • 2022-08-23
    • 2019-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多