我尝试从另一个控制器获取url作为参数后,在appcelerator中自动播放视频。但是视频没有播放。 这是VideoPalyerController.xml文件:
<Alloy>
<View class="container" >
<View class="videoPlayerView" >
<VideoPlayer class = "videoPlayerClass" id = "videoPlayer"></VideoPlayer>
</View>
<View class="videoInfoView" layout="vertical" backgroundColor="white">
<Label class="titleLabel" backgroundColor="gray"></Label>
<View class="dateUrlView" layout="horizontal"></View>
<Label class="dateLabel" backgroundColor="lightgray"></Label>
<Label class = "urlLabel"></Label>
</View>
<!-- <View class = "buttonview">
<Button class="backButton"></Button>
</View> -->
</View>
</Alloy>
这是VideoPlayerController.js文件:
var args = $.args;
Ti.API.trace("VideoPlayerController :",args.url);
//titleLabel = args.info;
$.videoPlayer.url = args.url;
这是DashboardController.js,我将参数发送到VideoPlayerController.js文件:
var args = $.args;
var sections = [];
//JSON to populate the listview
var videoInfo = [{
pic : "/Images/playButton.png",
info : "This in the the title for the first video.",
date : "03/07/2017",
url : "https://youtu.be/zkOSR0ZRb9khttps://youtu.be/zkOSR0ZRb9k"
}, {
pic : "/Images/playButton.png",
info : "This in the the title for the second video.",
date : "03/07/2017",
url : "https://youtu.be/zkOSR0ZRb9khttps://youtu.be/zkOSR0ZRb9k"
}, {
pic : "/Images/playButton.png",
info : "This in the the title for the third video.",
date : "03/07/2017",
url : "https://youtu.be/zkOSR0ZRb9khttps://youtu.be/zkOSR0ZRb9k"
}];
function populateListView() {
Ti.API.trace("[DashboardController.js >> populateListView() >>]");
if (!_.isEmpty(videoInfo)) {
for (var i = 0; i < videoInfo.length; i++) {
var item = {
template : "videoTemplate",
iconId : {
image : videoInfo[i].pic
},
titleId : {
text : videoInfo[i].info
},
dateId : {
text : videoInfo[i].date
},
urlId : {
text : videoInfo[i].url
},
properties : {
backgroundColor : "transparent"
}
};
sections.push(item);
}
$.listSection.setItems(sections);
}
}
populateListView();
$.lView.addEventListener('itemclick',function(e){
Ti.API.trace("[DashboardController.js >> Function to open VideoPlayerController >>]");
var dataItem = videoInfo[e.itemIndex];//$.listSection.getItemAt(e.itemIndex) ;
Ti.API.trace("Data Item is : ",dataItem);
var videoController = Alloy.createController('VideoPlayerController',{
"url":dataItem.url,
"title":dataItem.info,
"date":dataItem.date
}).getView();
Alloy.Globals.parent.add(videoController);
//videoController.open();
});
答案 0 :(得分:1)
您是否可以在浏览器上打开该视频? 因为当我试图从DashboardController.js文件中打开该URL时,它显示404错误。
我认为你在json对象中设置了两次url。
{
pic : "/Images/playButton.png",
info : "This in the the title for the second video.",
date : "03/07/2017",
url : "https://youtu.be/zkOSR0ZRb9khttps://youtu.be/zkOSR0ZRb9k"
}
再次删除其中一个。