2014-04-27 3 views
2

Sencha 터치 앱에서 작업 중입니다. 오디오 URL을 반환하는 jsonP 요청을 만들었습니다. 버튼 클릭으로 오디오를 재생하는 함수를 작성하고 싶습니다.Sencha Touch의 원격 서버에서 가져온 오디오 리소스 재생

Ext.data.JsonP.request({ 
        url: 'https://api.pearson.com/v2/dictionaries/entries', 
           callbackKey: 'callback', 
           params: { 
            apikey: 'ZzNOnelsRcNcE7Npoh2SdAeQbjRA4XE4', 
            headword: 'school' 
           } 

// RESPONSE..... 

{ 
    "status": 200, 
    "offset": 0, 
    "limit": 2, 
    "count": 2, 
    "total": 245, 
"url": "/v2/dictionaries/entries?headword=school&limit=2", 
    "results": [ 
{ 
    "datasets": [ 
    "ldoce5", 
    "dictionary" 
    ], 
    "headword": "school", 
    "homnum": 1, 
    "id": "cqAFqfYHHt", 
    "part_of_speech": "noun", 
    "senses": [ 
    { 
     "definition": "a place where children are taught", 
     "examples": [ 
     { 
      "audio": [ 
      { 
       "type": "example", 
       "url": "/v2/dictionaries/assets/ldoce/exa_pron/p008-001919005.mp3" // The audio url 
      } 
      ], 
      "text": "His mother always used to pick him up from school." 
     } 
     ], 
     "gramatical_info": { 
     "type": "uncountable and countable" 
     }, 
     "signpost": "where children learn" 
    } 
    ], 
    "url": "/v2/dictionaries/entries/cqAFqfYHHt" 
}, 
{ 
    "datasets": [ 
    "wordwise", 
    "dictionary" 
    ], 
    "headword": "school", 
    "id": "cqARFaW3Aw", 
    "part_of_speech": "noun", 
    "senses": [ 
    { 
     "definition": "a place where children are taught, or the time they spend there every day", 
     "examples": [ 
     { 
      "text": "Mr Mamood is a teacher at my school ." 
     } 
     ] 
    } 
    ], 
    "url": "/v2/dictionaries/entries/cqARFaW3Aw" 
    } 
    ] 
    } 

답변

1

당신은 그것을 숨기고, 센차 터치에서 제공하는 Ext.Audio 구성 요소를 사용할 수 있습니다 다음과 같이

전화의 구조와 반응입니다.

Ext.getCmp('audio').setUrl(mp3Url); 

는 그런 다음 플레이를 전환 버튼을 사용/일시 정지 그것에 :

{ 
    xtype: 'button', 
    text: 'Play' 
    handler: function() { 
     // get the audio component (using its id) 
     var audio = Ext.getCmp('audio'); 

     audio.toggle(); 
     this.setText(audio.isPlaying() ? 'Pause' : 'Play'); 
    } 
} 

확인 당신이 얻을로

{ 
    id: 'audio', 
    xtype: 'audio', 
    hidden: true, 
    url: null 
} 

는 즉시 오디오 URL이 구성 요소에 설정 예를 들면 http://docs.sencha.com/touch/2.3.1/#!/api/Ext.Audio.